/[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 74 - (show annotations) (download)
Sun Dec 17 22:44:31 2006 UTC (15 years, 5 months ago) by jeremyd2019
File MIME type: text/plain
File size: 4584 byte(s)
got progress bar working by setting s->end_pos to demuxer->movi_end prior to creating mpg demuxer.  Removed cruft from earlier attempts.  Copy eof states in tivo_stream_seek func to fix now that mpg demuxer seeks to end, hits eof, then unsets eof and seeks back to the beginning in course of probe

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 off_t begin_at;
25 off_t end_at;
26 } tivo_demux_priv;
27
28 m_option_t demux_tivo_opts[] = {
29 { "mak", &o_mak, CONF_TYPE_STRING,0, 0, 0, NULL },
30 {NULL, NULL, 0, 0, 0, 0, NULL}
31 };
32
33 static int mp_stream_read_wrapper (void * mem, int size, void * fh)
34 {
35 return stream_read ((stream_t *)fh, (char *)mem, size);
36 }
37
38 static int mp_packet_add_wrapper (void * mem, int size, void * fh)
39 {
40 demux_packet_t * dp = (demux_packet_t*)fh;
41 resize_demux_packet(dp, dp->pos + size);
42 memcpy(dp->buffer + dp->pos, mem, size);
43 return size;
44 }
45
46 int tivo_check_file(demuxer_t* demuxer)
47 {
48 int id = stream_read_dword_le(demuxer->stream);
49 stream_reset(demuxer->stream);
50 stream_seek(demuxer->stream, demuxer->movi_start);
51 if (id == mmioFOURCC('T', 'i', 'V', 'o'))
52 {
53 return DEMUXER_TYPE_TIVO;
54 }
55 return 0;
56 }
57
58 static int tivo_stream_seek(stream_t*s, off_t pos)
59 {
60 demux_stream_t* ds = s->priv;
61 int retval;
62 ds_free_packs (ds);
63 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "tivo_stream_seek to 0x%"PRIX64"\n", (int64_t)pos);
64 /* XXX reset eof if the other guy did */
65 ds->demuxer->stream->eof = s->eof;
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 /* XXX set other guy's eof if stream_seek set it */
69 s->eof = ds->demuxer->stream->eof;
70 return retval;
71 }
72
73 demuxer_t* demux_tivo_open(demuxer_t* demuxer)
74 {
75 tivo_demux_priv * priv = malloc(sizeof(tivo_demux_priv));
76 demuxer->priv = (void *)priv;
77
78 memset(priv, 0, sizeof(tivo_demux_priv));
79
80 priv->turing = malloc(sizeof(turing_state));
81 memset(priv->turing, 0, sizeof(turing_state));
82
83 priv->begin_at = setup_turing_key (priv->turing, demuxer->stream, &mp_stream_read_wrapper, o_mak);
84 mp_msg(MSGT_DEMUX, MSGL_STATUS, "begin_at = 0x%"PRIX64"\n", (int64_t)priv->begin_at);
85 stream_seek (demuxer->stream, priv->begin_at);
86 priv->end_at = demuxer->movi_end;
87
88 if (1)
89 {
90 extern int audio_id, video_id, dvdsub_id;
91 stream_t* s = new_ds_stream(demuxer->video);
92 demuxer_t* od;
93 s->seek = &tivo_stream_seek;
94 s->end_pos = priv->end_at - priv->begin_at;
95 od = demux_open(s, DEMUXER_TYPE_MPEG_PS,
96 audio_id, video_id, dvdsub_id, NULL);
97 demuxer = new_demuxers_demuxer(od, od, od);
98 }
99 return 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 ds_add_packet(ds, dp);
135 return 1;
136 }
137 else if (ret == 0)
138 {
139 dp->buffer[dp->pos++] = byte;
140 if (unlikely(dp->pos >= dp->len))
141 {
142 resize_demux_packet(dp, dp->pos);
143 demuxer->filepos = stream_tell(demuxer->stream) - priv->begin_at;
144 ds_add_packet(ds, dp);
145 dp = new_demux_packet (STREAM_BUFFER_SIZE);
146 }
147 }
148 else if (ret < 0)
149 {
150 perror ("processing frame");
151 return -1;
152 }
153 }
154 else if (!first)
155 {
156 dp->buffer[dp->pos++] = byte;
157 if (unlikely(dp->pos >= dp->len))
158 {
159 resize_demux_packet(dp, dp->pos);
160 demuxer->filepos = stream_tell(demuxer->stream) - priv->begin_at;
161 ds_add_packet(ds, dp);
162 dp = new_demux_packet (STREAM_BUFFER_SIZE);
163 }
164 }
165 marker <<= 8;
166 if ((rbyte = stream_read_char(demuxer->stream)) >= 0)
167 {
168 byte = (unsigned char)rbyte;
169 marker |= byte;
170 first=0;
171 }
172 }
173 return 0;
174 }
175
176 demuxer_desc_t demuxer_desc_tivo = {
177 "TiVoToGo file demuxer",
178 "ttg",
179 "TiVoToGo",
180 "Jeremy Drake",
181 "",
182 DEMUXER_TYPE_TIVO,
183 1, // safe autodetect
184 tivo_check_file,
185 demux_tivo_fill_buffer,
186 demux_tivo_open,
187 demux_tivo_close,
188 NULL,
189 NULL
190 };

cvs@jdrake.com
ViewVC Help
Powered by ViewVC 1.1.13