/[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 68 - (show annotations) (download)
Wed Dec 13 21:00:23 2006 UTC (15 years, 1 month ago) by jeremyd2019
File MIME type: text/plain
File size: 3153 byte(s)
add work-in-progress mplayer demuxer.  Is very hackish, need some help to clean it up.  Any volunteers?

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 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 resize_demux_packet(dp, size);
36 memcpy(dp->buffer, mem, size);
37 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 size_t begin_at;
56 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 if (1)
63 {
64 extern int audio_id, video_id, dvdsub_id;
65 stream_t* s = new_ds_stream(demuxer->video);
66 demuxer_t* od = demux_open(s, DEMUXER_TYPE_MPEG_PS,
67 audio_id, video_id, dvdsub_id, NULL);
68 demuxer = new_demuxers_demuxer(od, od, od);
69 }
70 return demuxer;
71 }
72
73 void demux_tivo_close(demuxer_t *demuxer)
74 {
75 turing_state * turing = demuxer->priv;
76
77 if (!turing)
78 return;
79
80 destruct_turing (turing);
81 free (turing);
82 }
83
84 int demux_tivo_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds)
85 {
86 off_t pak_start = stream_tell(demuxer->stream);
87 unsigned int marker;
88 unsigned char byte;
89 marker=0xFFFFFFFF;
90 while (!demuxer->stream->eof)
91 {
92 demux_packet_t * dp = new_demux_packet (1);
93 dp->pos = pak_start;
94 if ((marker & 0xFFFFFF00) == 0x100)
95 {
96 int ret;
97 ret = process_frame(byte, (turing_state *)(demuxer->priv), stream_tell(demuxer->stream), demuxer->stream, &mp_stream_read_wrapper, dp, &mp_packet_add_wrapper);
98 if (ret == 1)
99 {
100 marker = 0xFFFFFFFF;
101 ds_add_packet(ds, dp);
102 return 1;
103 }
104 else if (ret == 0)
105 {
106 mp_packet_add_wrapper(&byte, 1, dp);
107 ds_add_packet(ds, dp);
108 }
109 else if (ret < 0)
110 {
111 perror ("processing frame");
112 return -1;
113 }
114 }
115 else
116 {
117 mp_packet_add_wrapper(&byte, 1, dp);
118 ds_add_packet(ds, dp);
119 }
120 marker <<= 8;
121 if (stream_read(demuxer->stream, &byte, 1) == 0)
122 {
123 fprintf(stderr, "End of File\n");
124 demuxer->stream->eof = 1;
125 }
126 else
127 marker |= byte;
128 }
129 return 0;
130 }
131
132 demuxer_desc_t demuxer_desc_tivo = {
133 "TiVoToGo file demuxer",
134 "ttg",
135 "TiVoToGo",
136 "Jeremy Drake",
137 "",
138 DEMUXER_TYPE_TIVO,
139 1, // safe autodetect
140 tivo_check_file,
141 demux_tivo_fill_buffer,
142 demux_tivo_open,
143 demux_tivo_close,
144 NULL,
145 NULL
146 };

cvs@jdrake.com
ViewVC Help
Powered by ViewVC 1.1.13