annotate libmpdemux/demux_nut.c @ 23825:dc63f5657124

synced with r23342
author ptt
date Mon, 23 Jul 2007 12:37:16 +0000
parents 98a1fe0a8b0f
children f135a7260fd0
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>
20815
f58ac12a92b7 shut warning on "realloc undefined" in demuxer.h
ods15
parents: 20814
diff changeset
2 #include <stdlib.h>
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
3
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
4 #include "config.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
5 #include "mp_msg.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
6
23084
98a1fe0a8b0f compilation fix, manually include help_mp.h
ods15
parents: 23010
diff changeset
7 #include "help_mp.h"
98a1fe0a8b0f compilation fix, manually include help_mp.h
ods15
parents: 23010
diff changeset
8
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 22484
diff changeset
9 #include "stream/stream.h"
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
10 #include "demuxer.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
11 #include "stheader.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
12
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
13 #define USE_LIBNUT
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
14 #ifdef USE_LIBNUT
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
15
20893
ecb27a14d88d update to libnut, rename nut.h->libnut.h
ods15
parents: 20852
diff changeset
16 #include <libnut.h>
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
17
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
18 typedef struct {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
19 int last_pts; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
20 nut_context_t * nut;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
21 nut_stream_header_t * s;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
22 } nut_priv_t;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
23
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
24 static size_t mp_read(void * h, size_t len, uint8_t * buf) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
25 stream_t * stream = (stream_t*)h;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
26
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
27 if(stream_eof(stream)) return 0;
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
28 //len = MIN(len, 5);
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
29
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
30 return stream_read(stream, buf, len);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
31 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
32
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
33 static int mp_eof(void * h) {
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
34 stream_t * stream = (stream_t*)h;
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
35 if(stream_eof(stream)) return 1;
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
36 return 0;
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
37 }
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
38
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
39 static off_t mp_seek(void * h, long long pos, int whence) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
40 stream_t * stream = (stream_t*)h;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
41
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
42 if (stream->end_pos < stream_tell(stream))
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
43 stream->end_pos = stream_tell(stream);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
44
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
45 if (whence == SEEK_CUR) pos += stream_tell(stream);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
46 else if (whence == SEEK_END) pos += stream->end_pos;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
47 else if (whence != SEEK_SET) return -1;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
48
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
49 if (pos < stream->end_pos && stream->eof) stream_reset(stream);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
50 if (stream_seek(stream, pos) == 0) return -1;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
51
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
52 return pos;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
53 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
54
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
55 #define ID_STRING "nut/multimedia container"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
56 #define ID_LENGTH (strlen(ID_STRING) + 1)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
57
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
58 static int nut_check_file(demuxer_t * demuxer) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
59 uint8_t buf[ID_LENGTH];
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
60
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
61 if (stream_read(demuxer->stream, buf, ID_LENGTH) != ID_LENGTH) return 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
62
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
63 if (memcmp(buf, ID_STRING, ID_LENGTH)) return 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
64
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
65 stream_seek(demuxer->stream, 0);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
66 return DEMUXER_TYPE_NUT;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
67 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
68
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
69 static demuxer_t * demux_open_nut(demuxer_t * demuxer) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
70 extern int index_mode;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
71 nut_demuxer_opts_t dopts = {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
72 .input = {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
73 .priv = demuxer->stream,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
74 .seek = mp_seek,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
75 .read = mp_read,
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
76 .eof = mp_eof,
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
77 .file_pos = stream_tell(demuxer->stream),
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
78 },
19957
41153a5b5f8e sync to new libnut
ods15
parents: 19861
diff changeset
79 .alloc = { .malloc = NULL },
20909
fd91718e6c76 update to libnut, add cache_syncpoints
ods15
parents: 20893
diff changeset
80 .read_index = index_mode,
fd91718e6c76 update to libnut, add cache_syncpoints
ods15
parents: 20893
diff changeset
81 .cache_syncpoints = 1,
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
82 };
21011
b3fbda23e570 move demux_nut priv calloc to init() instead of check_file()
ods15
parents: 20971
diff changeset
83 nut_priv_t * priv = demuxer->priv = calloc(1, sizeof(nut_priv_t));
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
84 nut_context_t * nut = priv->nut = nut_demuxer_init(&dopts);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
85 nut_stream_header_t * s;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
86 int ret;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
87 int i;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
88
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
89 while ((ret = nut_read_headers(nut, &s, NULL)) == NUT_ERR_EAGAIN);
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
90 if (ret) {
20938
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
91 mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n", nut_error(ret));
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
92 nut_demuxer_uninit(nut);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
93 free(priv);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
94 return NULL;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
95 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
96
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
97 priv->s = s;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
98
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
99 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
100 case NUT_AUDIO_CLASS: {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
101 WAVEFORMATEX *wf =
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
102 calloc(sizeof(WAVEFORMATEX) +
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
103 s[i].codec_specific_len, 1);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
104 sh_audio_t* sh_audio = new_sh_audio(demuxer, i);
23010
74efb0fa8a0b with -identify show audio and video id; patch by Andrew Savchenko (Bircoph list ru)
nicodvb
parents: 22605
diff changeset
105 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_AudioID, "nut", i);
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
106 int j;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
107
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
108 sh_audio->wf= wf; sh_audio->ds = demuxer->audio;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
109 sh_audio->audio.dwSampleSize = 0; // FIXME
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
110 sh_audio->audio.dwScale = s[i].time_base.num;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
111 sh_audio->audio.dwRate = s[i].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
112 sh_audio->format = 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
113 for (j = 0; j < s[i].fourcc_len && j < 4; j++)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
114 sh_audio->format |= s[i].fourcc[j]<<(j*8);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
115 sh_audio->channels = s[i].channel_count;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
116 sh_audio->samplerate =
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
117 s[i].samplerate_num / s[i].samplerate_denom;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
118 sh_audio->i_bps = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
119
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
120 wf->wFormatTag = sh_audio->format;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
121 wf->nChannels = s[i].channel_count;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
122 wf->nSamplesPerSec =
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
123 s[i].samplerate_num / s[i].samplerate_denom;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
124 wf->nAvgBytesPerSec = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
125 wf->nBlockAlign = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
126 wf->wBitsPerSample = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
127 wf->cbSize = s[i].codec_specific_len;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
128 if (s[i].codec_specific_len)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
129 memcpy(wf + 1, s[i].codec_specific,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
130 s[i].codec_specific_len);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
131
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
132 demuxer->audio->id = i;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
133 demuxer->audio->sh= demuxer->a_streams[i];
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
134 break;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
135 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
136 case NUT_VIDEO_CLASS: {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
137 BITMAPINFOHEADER * bih =
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
138 calloc(sizeof(BITMAPINFOHEADER) +
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
139 s[i].codec_specific_len, 1);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
140 sh_video_t * sh_video = new_sh_video(demuxer, i);
23010
74efb0fa8a0b with -identify show audio and video id; patch by Andrew Savchenko (Bircoph list ru)
nicodvb
parents: 22605
diff changeset
141 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_VideoID, "nut", i);
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
142 int j;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
143
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
144 sh_video->bih = bih;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
145 sh_video->ds = demuxer->video;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
146 sh_video->disp_w = s[i].width;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
147 sh_video->disp_h = s[i].height;
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
148 sh_video->video.dwScale = s[i].time_base.num;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
149 sh_video->video.dwRate = s[i].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
150
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
151 sh_video->fps = sh_video->video.dwRate/
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
152 (float)sh_video->video.dwScale;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
153 sh_video->frametime = 1./sh_video->fps;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
154 sh_video->format = 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
155 for (j = 0; j < s[i].fourcc_len && j < 4; j++)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
156 sh_video->format |= s[i].fourcc[j]<<(j*8);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
157 if (!s[i].sample_height) sh_video->aspect = 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
158 else sh_video->aspect =
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
159 s[i].sample_width / (float)s[i].sample_height;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
160 sh_video->i_bps = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
161
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
162 bih->biSize = sizeof(BITMAPINFOHEADER) +
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
163 s[i].codec_specific_len;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
164 bih->biWidth = s[i].width;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
165 bih->biHeight = s[i].height;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
166 bih->biBitCount = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
167 bih->biSizeImage = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
168 bih->biCompression = sh_video->format;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
169
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
170 if (s[i].codec_specific_len)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
171 memcpy(bih + 1, s[i].codec_specific,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
172 s[i].codec_specific_len);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
173
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
174 demuxer->video->id = i;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
175 demuxer->video->sh = demuxer->v_streams[i];
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
176 break;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
177 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
178 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
179
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
180 return demuxer;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
181 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
182
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
183 static int demux_nut_fill_buffer(demuxer_t * demuxer, demux_stream_t * dsds) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
184 nut_priv_t * priv = demuxer->priv;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
185 nut_context_t * nut = priv->nut;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
186 demux_packet_t *dp;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
187 demux_stream_t *ds;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
188 nut_packet_t pd;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
189 int ret;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
190 double pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
191
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
192 demuxer->filepos = stream_tell(demuxer->stream);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
193 if (stream_eof(demuxer->stream)) return 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
194
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
195 while ((ret = nut_read_next_packet(nut, &pd)) == NUT_ERR_EAGAIN);
20938
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
196 if (ret) {
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
197 if (ret != NUT_ERR_EOF)
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
198 mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n",
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
199 nut_error(ret));
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
200 return 0; // fatal error
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
201 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
202
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
203 pts = (double)pd.pts * priv->s[pd.stream].time_base.num /
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
204 priv->s[pd.stream].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
205
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
206 if (pd.stream == demuxer->audio->id) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
207 ds = demuxer->audio;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
208 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
209 else if (pd.stream == demuxer->video->id) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
210 ds = demuxer->video;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
211 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
212 else {
20926
623e0adc71a2 update to libnut, no nut_skip_packet()
ods15
parents: 20925
diff changeset
213 uint8_t buf[pd.len];
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
214 while ((ret = nut_read_frame(nut, &pd.len, buf)) == NUT_ERR_EAGAIN);
20938
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
215 if (ret) {
19958
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
216 mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n",
20938
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
217 nut_error(ret));
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
218 return 0; // fatal error
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
219 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
220 return 1;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
221 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
222
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
223 if (pd.stream == 0) priv->last_pts = pd.pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
224
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
225 dp = new_demux_packet(pd.len);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
226
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
227 dp->pts = pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
228
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
229 dp->pos = demuxer->filepos;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
230 dp->flags= (pd.flags & NUT_FLAG_KEY) ? 0x10 : 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
231
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
232 {int len = pd.len;
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
233 while ((ret = nut_read_frame(nut, &len, dp->buffer + pd.len-len)) == NUT_ERR_EAGAIN);
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
234 }
20938
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
235 if (ret) {
19958
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
236 mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n",
20938
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
237 nut_error(ret));
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
238 return 0; // fatal error
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
239 }
19958
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
240
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
241 ds_add_packet(ds, dp); // append packet to DS stream
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
242 return 1;
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 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
246 nut_context_t * nut = ((nut_priv_t*)demuxer->priv)->nut;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
247 nut_priv_t * priv = demuxer->priv;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
248 sh_audio_t * sh_audio = demuxer->audio->sh;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
249 int nutflags = 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
250 int ret;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
251 const int tmp[] = { 0, -1 };
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
252
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
253 if (!(flags & 1)) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
254 nutflags |= 1; // relative
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
255 if (time_pos > 0) nutflags |= 2; // forwards
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
256 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
257
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
258 if (flags & 2) // percent
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
259 time_pos *= priv->s[0].max_pts *
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
260 (double)priv->s[0].time_base.num /
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
261 priv->s[0].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
262
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
263 while ((ret = nut_seek(nut, time_pos, nutflags, tmp)) == NUT_ERR_EAGAIN);
21023
f5180197d7ad fix demux_nut to give proper (estimate) of percent position after a seek
ods15
parents: 21022
diff changeset
264 priv->last_pts = -1;
20971
e243a3de18c2 missed piece in update to libnut API - non negative errors
ods15
parents: 20938
diff changeset
265 if (ret) mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n", nut_error(ret));
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
266 if (sh_audio) resync_audio_stream(sh_audio);
21023
f5180197d7ad fix demux_nut to give proper (estimate) of percent position after a seek
ods15
parents: 21022
diff changeset
267 demuxer->filepos = stream_tell(demuxer->stream);
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
268 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
269
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
270 static int demux_control_nut(demuxer_t * demuxer, int cmd, void * arg) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
271 nut_priv_t * priv = demuxer->priv;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
272 switch (cmd) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
273 case DEMUXER_CTRL_GET_TIME_LENGTH:
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
274 *((double *)arg) = priv->s[0].max_pts *
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
275 (double)priv->s[0].time_base.num /
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
276 priv->s[0].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
277 return DEMUXER_CTRL_OK;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
278 case DEMUXER_CTRL_GET_PERCENT_POS:
21023
f5180197d7ad fix demux_nut to give proper (estimate) of percent position after a seek
ods15
parents: 21022
diff changeset
279 if (priv->s[0].max_pts == 0 || priv->last_pts == -1)
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
280 return DEMUXER_CTRL_DONTKNOW;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
281 *((int *)arg) = priv->last_pts * 100 /
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
282 (double)priv->s[0].max_pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
283 return DEMUXER_CTRL_OK;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
284 default:
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
285 return DEMUXER_CTRL_NOTIMPL;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
286 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
287 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
288
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
289 static void demux_close_nut(demuxer_t *demuxer) {
20925
74b8d7cf4edb update to libnut API, don't free the streams
ods15
parents: 20909
diff changeset
290 nut_priv_t * priv = demuxer->priv;
21011
b3fbda23e570 move demux_nut priv calloc to init() instead of check_file()
ods15
parents: 20971
diff changeset
291 if (!priv) return;
20925
74b8d7cf4edb update to libnut API, don't free the streams
ods15
parents: 20909
diff changeset
292 nut_demuxer_uninit(priv->nut);
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
293 free(demuxer->priv);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
294 demuxer->priv = NULL;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
295 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
296
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
297
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
298 demuxer_desc_t demuxer_desc_nut = {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
299 "NUT demuxer",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
300 "nut",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
301 "libnut",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
302 "Oded Shimon (ods15)",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
303 "NUT demuxer, requires libnut",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
304 DEMUXER_TYPE_NUT,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
305 1, // safe check demuxer
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
306 nut_check_file,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
307 demux_nut_fill_buffer,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
308 demux_open_nut,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
309 demux_close_nut,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
310 demux_seek_nut,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
311 demux_control_nut
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
312 };
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
313
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
314 #endif // USE_LIBNUT
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
315