/[tivodecode]/mplayer_demuxer/trunk/demux_tivo.c
ViewVC logotype

Contents of /mplayer_demuxer/trunk/demux_tivo.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 73 - (show annotations) (download)
Sun Dec 17 22:20:25 2006 UTC (16 years, 1 month ago) by jeremyd2019
File MIME type: text/plain
File size: 5078 byte(s)
make a seek function for the stream that's handed to the mpg demuxer.  This seems sorta hackish but it allows me to seek in tivo files now.  Attempt to set movi_end and filepos for different demuxers in an attempt to get the progress bar to work.  Still not working, I believe because demux_mpg_open does not have movi_end initialized prior to it being called.

1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <memory.h>
5
6 #include "config.h"
7 #include "mp_msg.h"
8 #include "help_mp.h"
9 #include "m_option.h"
10
11 #include "stream.h"
12 #include "demuxer.h"
13 #include "stheader.h"
14
15 #include "turing_stream.h"
16 #include "tivodecoder.h"
17
18 int o_verbose = 0;
19 int o_no_verify = 0;
20 char * o_mak;
21
22 typedef struct {
23 turing_state * turing;
24 demuxer_t * mpg_demuxer;
25 demuxer_t * demux_demuxer;
26 off_t begin_at;
27 off_t end_at;
28 } tivo_demux_priv;
29
30 m_option_t demux_tivo_opts[] = {
31 { "mak", &o_mak, CONF_TYPE_STRING,0, 0, 0, NULL },
32 {NULL, NULL, 0, 0, 0, 0, NULL}
33 };
34
35 static int mp_stream_read_wrapper (void * mem, int size, void * fh)
36 {
37 return stream_read ((stream_t *)fh, (char *)mem, size);
38 }
39
40 static int mp_packet_add_wrapper (void * mem, int size, void * fh)
41 {
42 demux_packet_t * dp = (demux_packet_t*)fh;
43 resize_demux_packet(dp, dp->pos + size);
44 memcpy(dp->buffer + dp->pos, mem, size);
45 return size;
46 }
47
48 int tivo_check_file(demuxer_t* demuxer)
49 {
50 int id = stream_read_dword_le(demuxer->stream);
51 stream_reset(demuxer->stream);
52 stream_seek(demuxer->stream, demuxer->movi_start);
53 if (id == mmioFOURCC('T', 'i', 'V', 'o'))
54 {
55 return DEMUXER_TYPE_TIVO;
56 }
57 return 0;
58 }
59
60 static int tivo_stream_seek(stream_t*s, off_t pos)
61 {
62 demux_stream_t* ds = s->priv;
63 int retval;
64 ds_free_packs (ds);
65 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "tivo_stream_seek to 0x%"PRIX64"\n", (int64_t)pos);
66 retval = stream_seek(ds->demuxer->stream, ((tivo_demux_priv*)ds->demuxer->priv)->begin_at + pos);
67 s->pos = ds->dpos = stream_tell(ds->demuxer->stream) - ((tivo_demux_priv*)ds->demuxer->priv)->begin_at;
68 return retval;
69 }
70
71 demuxer_t* demux_tivo_open(demuxer_t* demuxer)
72 {
73 tivo_demux_priv * priv = malloc(sizeof(tivo_demux_priv));
74 demuxer->priv = (void *)priv;
75
76 memset(priv, 0, sizeof(tivo_demux_priv));
77
78 priv->turing = malloc(sizeof(turing_state));
79 memset(priv->turing, 0, sizeof(turing_state));
80
81 priv->begin_at = setup_turing_key (priv->turing, demuxer->stream, &mp_stream_read_wrapper, o_mak);
82 mp_msg(MSGT_DEMUX, MSGL_STATUS, "begin_at = 0x%"PRIX64"\n", (int64_t)priv->begin_at);
83 stream_seek (demuxer->stream, priv->begin_at);
84 priv->end_at = demuxer->movi_end;
85
86 if (1)
87 {
88 extern int audio_id, video_id, dvdsub_id;
89 stream_t* s = new_ds_stream(demuxer->video);
90 s->seek = &tivo_stream_seek;
91 priv->mpg_demuxer = demux_open(s, DEMUXER_TYPE_MPEG_PS,
92 audio_id, video_id, dvdsub_id, NULL);
93 /* XXX Can't get movi_end initialized at the right point */
94 priv->mpg_demuxer->movi_end = priv->end_at;
95 priv->demux_demuxer = new_demuxers_demuxer(priv->mpg_demuxer, priv->mpg_demuxer, priv->mpg_demuxer);
96 /* XXX Can't get movi_end initialized at the right point */
97 priv->demux_demuxer->movi_end = priv->end_at;
98 }
99 return priv->demux_demuxer;
100 }
101
102 void demux_tivo_close(demuxer_t *demuxer)
103 {
104 tivo_demux_priv * priv = demuxer->priv;
105
106 if (!priv)
107 return;
108
109 destruct_turing (priv->turing);
110 free (priv->turing);
111 free (priv);
112 }
113
114 int demux_tivo_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds)
115 {
116 demux_packet_t * dp;
117 tivo_demux_priv * priv = demuxer->priv;
118 unsigned int marker = 0xFFFFFFFF;
119 int rbyte;
120 unsigned char byte = 0xFF;
121 char first = 1;
122
123 dp = new_demux_packet (STREAM_BUFFER_SIZE);
124
125 while (!demuxer->stream->eof)
126 {
127 if ((marker & 0xFFFFFF00) == 0x100)
128 {
129 int ret = process_frame(byte, priv->turing, stream_tell(demuxer->stream), demuxer->stream, &mp_stream_read_wrapper, dp, &mp_packet_add_wrapper);
130 if (ret == 1)
131 {
132 marker = 0xFFFFFFFF;
133 demuxer->filepos = stream_tell(demuxer->stream) - priv->begin_at;
134 /* XXX setting demux_demuxers filepos */
135 if(priv->demux_demuxer) priv->demux_demuxer->filepos = demuxer->filepos;
136 ds_add_packet(ds, dp);
137 return 1;
138 }
139 else if (ret == 0)
140 {
141 dp->buffer[dp->pos++] = byte;
142 if (unlikely(dp->pos >= dp->len))
143 {
144 resize_demux_packet(dp, dp->pos);
145 demuxer->filepos = stream_tell(demuxer->stream) - priv->begin_at;
146 /* XXX setting demux_demuxers filepos */
147 if(priv->demux_demuxer) priv->demux_demuxer->filepos = demuxer->filepos;
148 ds_add_packet(ds, dp);
149 dp = new_demux_packet (STREAM_BUFFER_SIZE);
150 }
151 }
152 else if (ret < 0)
153 {
154 perror ("processing frame");
155 return -1;
156 }
157 }
158 else if (!first)
159 {
160 dp->buffer[dp->pos++] = byte;
161 if (unlikely(dp->pos >= dp->len))
162 {
163 resize_demux_packet(dp, dp->pos);
164 demuxer->filepos = stream_tell(demuxer->stream) - priv->begin_at;
165 /* XXX setting demux_demuxers filepos */
166 if(priv->demux_demuxer) priv->demux_demuxer->filepos = demuxer->filepos;
167 ds_add_packet(ds, dp);
168 dp = new_demux_packet (STREAM_BUFFER_SIZE);
169 }
170 }
171 marker <<= 8;
172 if ((rbyte = stream_read_char(demuxer->stream)) >= 0)
173 {
174 byte = (unsigned char)rbyte;
175 marker |= byte;
176 first=0;
177 }
178 }
179 return 0;
180 }
181
182 demuxer_desc_t demuxer_desc_tivo = {
183 "TiVoToGo file demuxer",
184 "ttg",
185 "TiVoToGo",
186 "Jeremy Drake",
187 "",
188 DEMUXER_TYPE_TIVO,
189 1, // safe autodetect
190 tivo_check_file,
191 demux_tivo_fill_buffer,
192 demux_tivo_open,
193 demux_tivo_close,
194 NULL,
195 NULL
196 };

cvs@jdrake.com
ViewVC Help
Powered by ViewVC 1.1.13