annotate libmpdemux/demux_nut.c @ 20416:c7f0452a93c0

Remove modification notice from unmodified file.
author diego
date Tue, 24 Oct 2006 17:41:16 +0000
parents e50391b26740
children c3e142d35fac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
1 #include <stdio.h>
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
2
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
3 #include "config.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
4 #include "mp_msg.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
5
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
6 #include "stream.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
7 #include "demuxer.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
8 #include "stheader.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
9
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
10 #define USE_LIBNUT
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
11 #ifdef USE_LIBNUT
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
12
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
13 #include "nut.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
14
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
15 typedef struct {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
16 int last_pts; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
17 nut_context_t * nut;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
18 nut_stream_header_t * s;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
19 } nut_priv_t;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
20
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
21 static size_t mp_read(void * h, size_t len, uint8_t * buf) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
22 stream_t * stream = (stream_t*)h;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
23
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
24 if(stream_eof(stream)) return 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
25
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
26 return stream_read(stream, buf, len);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
27 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
28
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
29 static off_t mp_seek(void * h, long long pos, int whence) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
30 stream_t * stream = (stream_t*)h;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
31
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
32 if (stream->end_pos < stream_tell(stream))
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
33 stream->end_pos = stream_tell(stream);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
34
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
35 if (whence == SEEK_CUR) pos += stream_tell(stream);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
36 else if (whence == SEEK_END) pos += stream->end_pos;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
37 else if (whence != SEEK_SET) return -1;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
38
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
39 if (pos < stream->end_pos && stream->eof) stream_reset(stream);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
40 if (stream_seek(stream, pos) == 0) return -1;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
41
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
42 return pos;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
43 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
44
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
45 #define ID_STRING "nut/multimedia container"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
46 #define ID_LENGTH (strlen(ID_STRING) + 1)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
47
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
48 static int nut_check_file(demuxer_t * demuxer) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
49 uint8_t buf[ID_LENGTH];
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
50 nut_priv_t * priv = demuxer->priv = calloc(1, sizeof(nut_priv_t));
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
51
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
52 if (stream_read(demuxer->stream, buf, ID_LENGTH) != ID_LENGTH) return 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
53
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
54 if (memcmp(buf, ID_STRING, ID_LENGTH)) return 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
55
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
56 stream_seek(demuxer->stream, 0);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
57 return DEMUXER_TYPE_NUT;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
58 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
59
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
60 static demuxer_t * demux_open_nut(demuxer_t * demuxer) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
61 extern int index_mode;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
62 nut_demuxer_opts_t dopts = {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
63 .input = {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
64 .priv = demuxer->stream,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
65 .seek = mp_seek,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
66 .read = mp_read,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
67 .eof = NULL,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
68 .file_pos = stream_tell(demuxer->stream),
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
69 },
19957
41153a5b5f8e sync to new libnut
ods15
parents: 19861
diff changeset
70 .alloc = { .malloc = NULL },
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
71 .read_index = index_mode
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
72 };
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
73 nut_priv_t * priv = demuxer->priv;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
74 nut_context_t * nut = priv->nut = nut_demuxer_init(&dopts);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
75 nut_stream_header_t * s;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
76 int ret;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
77 int i;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
78
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
79 if ((ret = nut_read_headers(nut, &s))) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
80 if (ret < 0) mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
81 nut_error(-ret));
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
82 nut_demuxer_uninit(nut);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
83 free(priv);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
84 return NULL;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
85 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
86
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
87 priv->s = s;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
88
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
89 for (i = 0; s[i].type != -1 && i < 2; i++) switch(s[i].type) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
90 case NUT_AUDIO_CLASS: {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
91 WAVEFORMATEX *wf =
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
92 calloc(sizeof(WAVEFORMATEX) +
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
93 s[i].codec_specific_len, 1);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
94 sh_audio_t* sh_audio = new_sh_audio(demuxer, i);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
95 int j;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
96
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
97 sh_audio->wf= wf; sh_audio->ds = demuxer->audio;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
98 sh_audio->audio.dwSampleSize = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
99 sh_audio->audio.dwScale = s[i].time_base.nom;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
100 sh_audio->audio.dwRate = s[i].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
101 sh_audio->format = 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
102 for (j = 0; j < s[i].fourcc_len && j < 4; j++)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
103 sh_audio->format |= s[i].fourcc[j]<<(j*8);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
104 sh_audio->channels = s[i].channel_count;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
105 sh_audio->samplerate =
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
106 s[i].samplerate_nom / s[i].samplerate_denom;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
107 sh_audio->i_bps = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
108
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
109 wf->wFormatTag = sh_audio->format;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
110 wf->nChannels = s[i].channel_count;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
111 wf->nSamplesPerSec =
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
112 s[i].samplerate_nom / s[i].samplerate_denom;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
113 wf->nAvgBytesPerSec = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
114 wf->nBlockAlign = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
115 wf->wBitsPerSample = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
116 wf->cbSize = s[i].codec_specific_len;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
117 if (s[i].codec_specific_len)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
118 memcpy(wf + 1, s[i].codec_specific,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
119 s[i].codec_specific_len);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
120
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
121 demuxer->audio->id = i;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
122 demuxer->audio->sh= demuxer->a_streams[i];
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
123 break;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
124 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
125 case NUT_VIDEO_CLASS: {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
126 BITMAPINFOHEADER * bih =
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
127 calloc(sizeof(BITMAPINFOHEADER) +
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
128 s[i].codec_specific_len, 1);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
129 sh_video_t * sh_video = new_sh_video(demuxer, i);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
130 int j;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
131
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
132 sh_video->bih = bih;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
133 sh_video->ds = demuxer->video;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
134 sh_video->disp_w = s[i].width;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
135 sh_video->disp_h = s[i].height;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
136 sh_video->video.dwScale = s[i].time_base.nom;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
137 sh_video->video.dwRate = s[i].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
138
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
139 sh_video->fps = sh_video->video.dwRate/
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
140 (float)sh_video->video.dwScale;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
141 sh_video->frametime = 1./sh_video->fps;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
142 sh_video->format = 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
143 for (j = 0; j < s[i].fourcc_len && j < 4; j++)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
144 sh_video->format |= s[i].fourcc[j]<<(j*8);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
145 if (!s[i].sample_height) sh_video->aspect = 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
146 else sh_video->aspect =
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
147 s[i].sample_width / (float)s[i].sample_height;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
148 sh_video->i_bps = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
149
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
150 bih->biSize = sizeof(BITMAPINFOHEADER) +
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
151 s[i].codec_specific_len;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
152 bih->biWidth = s[i].width;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
153 bih->biHeight = s[i].height;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
154 bih->biBitCount = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
155 bih->biSizeImage = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
156 bih->biCompression = sh_video->format;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
157
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
158 if (s[i].codec_specific_len)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
159 memcpy(bih + 1, s[i].codec_specific,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
160 s[i].codec_specific_len);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
161
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
162 demuxer->video->id = i;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
163 demuxer->video->sh = demuxer->v_streams[i];
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
164 break;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
165 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
166 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
167
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
168 return demuxer;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
169 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
170
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
171 static int demux_nut_fill_buffer(demuxer_t * demuxer, demux_stream_t * dsds) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
172 nut_priv_t * priv = demuxer->priv;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
173 nut_context_t * nut = priv->nut;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
174 demux_packet_t *dp;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
175 demux_stream_t *ds;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
176 nut_packet_t pd;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
177 int ret;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
178 double pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
179
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
180 demuxer->filepos = stream_tell(demuxer->stream);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
181 if (stream_eof(demuxer->stream)) return 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
182
19958
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
183 ret = nut_read_next_packet(nut, &pd);
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
184 if (ret < 0) {
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
185 mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n",
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
186 nut_error(-ret));
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
187 }
19958
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
188 if (ret) return 0; // fatal error
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
189
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
190 pts = (double)pd.pts * priv->s[pd.stream].time_base.nom /
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
191 priv->s[pd.stream].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
192
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
193 if (pd.stream == demuxer->audio->id) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
194 ds = demuxer->audio;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
195 if (!demuxer->video->sh) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
196 ((sh_audio_t*)ds->sh)->delay = pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
197 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
198 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
199 else if (pd.stream == demuxer->video->id) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
200 ds = demuxer->video;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
201 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
202 else {
19958
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
203 ret = nut_skip_packet(nut, &pd.len);
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
204 if (ret < 0) {
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
205 mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n",
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
206 nut_error(-ret));
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
207 }
19958
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
208 if (ret) return 0; // fatal error
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
209 return 1;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
210 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
211
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
212 if (pd.stream == 0) priv->last_pts = pd.pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
213
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
214 dp = new_demux_packet(pd.len);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
215
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
216 dp->pts = pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
217
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
218 dp->pos = demuxer->filepos;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
219 dp->flags= (pd.flags & NUT_FLAG_KEY) ? 0x10 : 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
220
19958
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
221 ret = nut_read_frame(nut, &pd.len, dp->buffer);
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
222 if (ret < 0) {
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
223 mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n",
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
224 nut_error(-ret));
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
225 }
19958
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
226 if (ret) return 0; // fatal error
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
227
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
228 ds_add_packet(ds, dp); // append packet to DS stream
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
229 return 1;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
230 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
231
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
232 static void demux_seek_nut(demuxer_t * demuxer, float time_pos, float audio_delay, int flags) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
233 nut_context_t * nut = ((nut_priv_t*)demuxer->priv)->nut;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
234 nut_priv_t * priv = demuxer->priv;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
235 sh_audio_t * sh_audio = demuxer->audio->sh;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
236 int nutflags = 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
237 int ret;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
238 const int tmp[] = { 0, -1 };
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
239
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
240 if (!(flags & 1)) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
241 nutflags |= 1; // relative
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
242 if (time_pos > 0) nutflags |= 2; // forwards
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
243 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
244
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
245 if (flags & 2) // percent
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
246 time_pos *= priv->s[0].max_pts *
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
247 (double)priv->s[0].time_base.nom /
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
248 priv->s[0].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
249
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
250 ret = nut_seek(nut, time_pos, nutflags, tmp);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
251 if (ret < 0)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
252 mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n", nut_error(-ret));
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
253 if (sh_audio) resync_audio_stream(sh_audio);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
254 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
255
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
256 static int demux_control_nut(demuxer_t * demuxer, int cmd, void * arg) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
257 nut_priv_t * priv = demuxer->priv;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
258 switch (cmd) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
259 case DEMUXER_CTRL_GET_TIME_LENGTH:
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
260 *((double *)arg) = priv->s[0].max_pts *
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
261 (double)priv->s[0].time_base.nom /
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
262 priv->s[0].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
263 return DEMUXER_CTRL_OK;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
264 case DEMUXER_CTRL_GET_PERCENT_POS:
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
265 if (priv->s[0].max_pts == 0)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
266 return DEMUXER_CTRL_DONTKNOW;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
267 *((int *)arg) = priv->last_pts * 100 /
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
268 (double)priv->s[0].max_pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
269 return DEMUXER_CTRL_OK;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
270 default:
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
271 return DEMUXER_CTRL_NOTIMPL;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
272 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
273 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
274
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
275 static void demux_close_nut(demuxer_t *demuxer) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
276 nut_context_t * nut = ((nut_priv_t*)demuxer->priv)->nut;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
277 nut_demuxer_uninit(nut);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
278 free(((nut_priv_t*)demuxer->priv)->s);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
279 free(demuxer->priv);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
280 demuxer->priv = NULL;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
281 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
282
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
283
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
284 demuxer_desc_t demuxer_desc_nut = {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
285 "NUT demuxer",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
286 "nut",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
287 "libnut",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
288 "Oded Shimon (ods15)",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
289 "NUT demuxer, requires libnut",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
290 DEMUXER_TYPE_NUT,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
291 1, // safe check demuxer
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
292 nut_check_file,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
293 demux_nut_fill_buffer,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
294 demux_open_nut,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
295 demux_close_nut,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
296 demux_seek_nut,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
297 demux_control_nut
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
298 };
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
299
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
300 #endif // USE_LIBNUT
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
301