/[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 72 - (hide annotations) (download)
Sun Dec 17 02:05:07 2006 UTC (15 years, 5 months ago) by jeremyd2019
File MIME type: text/plain
File size: 3651 byte(s)
set demuxer->filepos before ds_add_packet, noticed that movi_start and movi_end on mpeg demuxer were not set, so set them, still not getting progress bar though

1 jeremyd2019 68 #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     m_option_t demux_tivo_opts[] = {
23     { "mak", &o_mak, CONF_TYPE_STRING,0, 0, 0, NULL },
24     {NULL, NULL, 0, 0, 0, 0, NULL}
25     };
26    
27     static int mp_stream_read_wrapper (void * mem, int size, void * fh)
28     {
29     return stream_read ((stream_t *)fh, (char *)mem, size);
30     }
31    
32     static int mp_packet_add_wrapper (void * mem, int size, void * fh)
33     {
34     demux_packet_t * dp = (demux_packet_t*)fh;
35 jeremyd2019 71 resize_demux_packet(dp, dp->pos + size);
36     memcpy(dp->buffer + dp->pos, mem, size);
37 jeremyd2019 68 return size;
38     }
39    
40     int tivo_check_file(demuxer_t* demuxer)
41     {
42     int id = stream_read_dword_le(demuxer->stream);
43     stream_reset(demuxer->stream);
44     stream_seek(demuxer->stream, demuxer->movi_start);
45     if (id == mmioFOURCC('T', 'i', 'V', 'o'))
46     {
47     return DEMUXER_TYPE_TIVO;
48     }
49     return 0;
50     }
51    
52     demuxer_t* demux_tivo_open(demuxer_t* demuxer)
53     {
54     turing_state *turing;
55 jeremyd2019 72 off_t begin_at, end_at;
56 jeremyd2019 68 turing = malloc(sizeof(turing_state));
57     memset(turing, 0, sizeof(turing_state));
58     demuxer->priv = (void *)turing;
59     begin_at = setup_turing_key (turing, demuxer->stream, &mp_stream_read_wrapper, o_mak);
60     fprintf(stderr, "begin_at = %lx\n", begin_at);
61     stream_seek (demuxer->stream, begin_at);
62 jeremyd2019 72 end_at = demuxer->movi_end;
63 jeremyd2019 68 if (1)
64     {
65     extern int audio_id, video_id, dvdsub_id;
66     stream_t* s = new_ds_stream(demuxer->video);
67     demuxer_t* od = demux_open(s, DEMUXER_TYPE_MPEG_PS,
68     audio_id, video_id, dvdsub_id, NULL);
69     demuxer = new_demuxers_demuxer(od, od, od);
70 jeremyd2019 72 demuxer->movi_start = begin_at;
71     demuxer->movi_end = end_at;
72 jeremyd2019 68 }
73     return demuxer;
74     }
75    
76     void demux_tivo_close(demuxer_t *demuxer)
77     {
78     turing_state * turing = demuxer->priv;
79    
80     if (!turing)
81     return;
82    
83     destruct_turing (turing);
84     free (turing);
85     }
86    
87     int demux_tivo_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds)
88     {
89 jeremyd2019 71 demux_packet_t * dp;
90 jeremyd2019 68 unsigned int marker;
91 jeremyd2019 69 int rbyte;
92 jeremyd2019 68 unsigned char byte;
93 jeremyd2019 69 char first = 1;
94 jeremyd2019 68 marker=0xFFFFFFFF;
95 jeremyd2019 71 dp = new_demux_packet (STREAM_BUFFER_SIZE);
96 jeremyd2019 70
97 jeremyd2019 68 while (!demuxer->stream->eof)
98     {
99     if ((marker & 0xFFFFFF00) == 0x100)
100     {
101 jeremyd2019 71 int ret = process_frame(byte, (turing_state *)(demuxer->priv), stream_tell(demuxer->stream), demuxer->stream, &mp_stream_read_wrapper, dp, &mp_packet_add_wrapper);
102 jeremyd2019 68 if (ret == 1)
103     {
104     marker = 0xFFFFFFFF;
105 jeremyd2019 72 demuxer->filepos = stream_tell(demuxer->stream);
106 jeremyd2019 68 ds_add_packet(ds, dp);
107     return 1;
108     }
109     else if (ret == 0)
110     {
111 jeremyd2019 71 dp->buffer[dp->pos++] = byte;
112     if (unlikely(dp->pos >= dp->len))
113 jeremyd2019 70 {
114 jeremyd2019 71 resize_demux_packet(dp, dp->pos);
115 jeremyd2019 72 demuxer->filepos = stream_tell(demuxer->stream);
116 jeremyd2019 70 ds_add_packet(ds, dp);
117     dp = new_demux_packet (STREAM_BUFFER_SIZE);
118     }
119 jeremyd2019 68 }
120     else if (ret < 0)
121     {
122     perror ("processing frame");
123     return -1;
124     }
125     }
126 jeremyd2019 69 else if (!first)
127 jeremyd2019 68 {
128 jeremyd2019 71 dp->buffer[dp->pos++] = byte;
129     if (unlikely(dp->pos >= dp->len))
130 jeremyd2019 70 {
131 jeremyd2019 71 resize_demux_packet(dp, dp->pos);
132 jeremyd2019 72 demuxer->filepos = stream_tell(demuxer->stream);
133 jeremyd2019 70 ds_add_packet(ds, dp);
134     dp = new_demux_packet (STREAM_BUFFER_SIZE);
135     }
136 jeremyd2019 68 }
137     marker <<= 8;
138 jeremyd2019 69 if ((rbyte = stream_read_char(demuxer->stream)) >= 0)
139 jeremyd2019 68 {
140 jeremyd2019 69 byte = (unsigned char)rbyte;
141     marker |= byte;
142     first=0;
143 jeremyd2019 68 }
144     }
145     return 0;
146     }
147    
148     demuxer_desc_t demuxer_desc_tivo = {
149     "TiVoToGo file demuxer",
150     "ttg",
151     "TiVoToGo",
152     "Jeremy Drake",
153     "",
154     DEMUXER_TYPE_TIVO,
155     1, // safe autodetect
156     tivo_check_file,
157     demux_tivo_fill_buffer,
158     demux_tivo_open,
159     demux_tivo_close,
160     NULL,
161     NULL
162     };

cvs@jdrake.com
ViewVC Help
Powered by ViewVC 1.1.13