/[tivodecode]/tivocom/trunk/CChunkCollection.cpp
ViewVC logotype

Contents of /tivocom/trunk/CChunkCollection.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 254 - (show annotations) (download)
Sun Sep 9 23:26:20 2007 UTC (14 years, 4 months ago) by jeremyd2019
File size: 1773 byte(s)
rework interfaces (bumped typelib version to 1.1).  Add support for decoding the MPEG stream.  Added support to read and write from streams (implementing IStream) and make the versions which take filenames use a stream implementation that wraps file access.  Make OpenTivoFile take the MAK as a parameter.  It has a default value of "" (empty string), which means try to get the MAK from the registry, so either omit that param (for those languages which permit that) or specify it as empty string to use the MAK from the registry.  Added progress reporting of MPEG stream decoding via a connection point.  Progress is updated every 100 frames, and percent complete is provided if the tivo file stream supports Seek and Stat functions

1 // CChunkCollection.cpp : Implementation of CChunkCollection
2
3 #include "stdafx.h"
4 #include "CChunkCollection.h"
5
6 // CChunkCollection
7
8 namespace
9 {
10 class CopyTivoChunk
11 {
12 public:
13 static HRESULT copy(VARIANT * p1, const CComPtr<ITivoChunk> * p2)
14 {
15 ATLENSURE(p1 != NULL && p2 != NULL);
16 CComVariant var (*p2);
17 return var.Detach(p1);
18 }
19 static void init(VARIANT* p) {VariantInit(p);}
20 static void destroy(VARIANT* p) {VariantClear(p);}
21 };
22
23 } // end anon namespace
24
25
26 STDMETHODIMP CChunkCollection::Init(const std::string & mak, USHORT nChunks, ULARGE_INTEGER* chunk_pos, IStream* pStm)
27 {
28 try
29 {
30 m_chunks.resize(nChunks);
31 for (USHORT i = 0; i < nChunks; ++i)
32 {
33 CTivoChunk *chunk = new CComObject<CTivoChunk> ();
34 m_chunks[i] = chunk;
35 _com_util::CheckError(chunk->Init (mak, m_chunks[0], pStm, chunk_pos));
36 }
37 }
38 catch (const _com_error & ex)
39 {
40 return ex.Error();
41 }
42 return S_OK;
43 }
44
45
46
47 STDMETHODIMP CChunkCollection::get_Count(long* pVal)
48 {
49 if (!pVal)
50 return E_POINTER;
51
52 *pVal = static_cast<long>(m_chunks.size());
53 return S_OK;
54 }
55
56 STDMETHODIMP CChunkCollection::get_Item(long Index, ITivoChunk** pVal)
57 {
58 if (Index < 1 || static_cast<size_t>(Index) > m_chunks.size())
59 return E_INVALIDARG;
60
61 return m_chunks[Index-1].CopyTo(pVal);
62 }
63
64 STDMETHODIMP CChunkCollection::get__NewEnum(IUnknown** pVal)
65 {
66 typedef CComEnumOnSTL<IEnumVARIANT, &IID_IEnumVARIANT, VARIANT, CopyTivoChunk, std::vector<CComPtr<ITivoChunk> > > EnumType;
67 try
68 {
69 CComObject<EnumType>* foo;
70 _com_util::CheckError(CComObject<EnumType>::CreateInstance(&foo));
71 CComPtr<IUnknown> retval = foo;
72 _com_util::CheckError(foo->Init (GetUnknown(), m_chunks));
73 _com_util::CheckError(retval.CopyTo(pVal));
74 }
75 catch (const _com_error & ex)
76 {
77 return ex.Error();
78 }
79
80 return S_OK;
81 }

cvs@jdrake.com
ViewVC Help
Powered by ViewVC 1.1.13