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

Contents of /tivocom/trunk/CTivoChunk.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: 1713 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 // CTivoChunk.cpp : Implementation of CTivoChunk
2
3 #include "stdafx.h"
4 #include "CTivoChunk.h"
5
6 extern "C" {
7 int stream_read_wrapper(void* mem, int size, void* fh);
8 }
9
10 // CTivoChunk
11
12 STDMETHODIMP CTivoChunk::Init(const std::string & mak, ITivoChunk *chunk0, IStream* pStm, ULARGE_INTEGER* pChunkPos)
13 {
14 m_chunkstart = *pChunkPos;
15 m_chunk = read_tivo_chunk(pStm, stream_read_wrapper);
16 if (!m_chunk)
17 return E_FAIL;
18 if (m_chunk->type != TIVO_CHUNK_XML)
19 m_chunk0 = chunk0;
20
21 m_mak = mak;
22
23 pChunkPos->QuadPart += m_chunk->chunk_size;
24
25 return S_OK;
26 }
27
28 STDMETHODIMP CTivoChunk::get_chunk_size(UINT* pVal)
29 {
30 if (!pVal)
31 return E_POINTER;
32
33 *pVal = m_chunk->chunk_size;
34
35 return S_OK;
36 }
37
38 STDMETHODIMP CTivoChunk::get_data_size(UINT* pVal)
39 {
40 if (!pVal)
41 return E_POINTER;
42
43 *pVal = m_chunk->data_size;
44
45 return S_OK;
46 }
47
48 STDMETHODIMP CTivoChunk::get_chunk_id(USHORT* pVal)
49 {
50 if (!pVal)
51 return E_POINTER;
52
53 *pVal = m_chunk->id;
54
55 return S_OK;
56 }
57
58 STDMETHODIMP CTivoChunk::get_chunk_type(USHORT* pVal)
59 {
60 if (!pVal)
61 return E_POINTER;
62
63 *pVal = m_chunk->type;
64
65 return S_OK;
66 }
67
68 STDMETHODIMP CTivoChunk::get_data(BSTR* pVal)
69 {
70 do
71 {
72 if (m_chunk->type == TIVO_CHUNK_XML || m_decrypted)
73 {
74 CComBSTR retval (m_chunk->data_size, reinterpret_cast<char*>(m_chunk->data));
75 return retval.CopyTo(pVal);
76 }
77
78 turing_state metaturing = {0};
79 setup_metadata_key (&metaturing, dynamic_cast<CTivoChunk*> (m_chunk0.p)->m_chunk, const_cast<char*>(m_mak.c_str()));
80 prepare_frame(&metaturing, 0, 0);
81 skip_turing_data(&metaturing, m_chunkstart.QuadPart + SIZEOF_STREAM_CHUNK);
82 decrypt_buffer(&metaturing, m_chunk->data, m_chunk->data_size);
83 destruct_turing(&metaturing);
84
85 m_decrypted = true;
86 } while(1);
87 }

cvs@jdrake.com
ViewVC Help
Powered by ViewVC 1.1.13