annotate libmpdemux/demux_nut.c @ 34444:bf52ce065c12

Add a script to help update the references.
author reimar
date Sun, 08 Jan 2012 10:44:00 +0000
parents a86413775fbe
children 139f2b064ef9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29238
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
1 /*
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
2 * This file is part of MPlayer.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
3 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
5 * it under the terms of the GNU General Public License as published by
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
7 * (at your option) any later version.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
8 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
12 * GNU General Public License for more details.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
13 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
14 * You should have received a copy of the GNU General Public License along
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
17 */
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28101
diff changeset
18
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
19 #include <stdio.h>
20815
f58ac12a92b7 shut warning on "realloc undefined" in demuxer.h
ods15
parents: 20814
diff changeset
20 #include <stdlib.h>
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
21
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
22 #include "config.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
23 #include "mp_msg.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
24
23084
98a1fe0a8b0f compilation fix, manually include help_mp.h
ods15
parents: 23010
diff changeset
25 #include "help_mp.h"
98a1fe0a8b0f compilation fix, manually include help_mp.h
ods15
parents: 23010
diff changeset
26
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 22484
diff changeset
27 #include "stream/stream.h"
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
28 #include "demuxer.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
29 #include "stheader.h"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
30
20893
ecb27a14d88d update to libnut, rename nut.h->libnut.h
ods15
parents: 20852
diff changeset
31 #include <libnut.h>
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
32
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
33 typedef struct {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
34 int last_pts; // FIXME
28099
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
35 nut_context_tt * nut;
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
36 nut_stream_header_tt * s;
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
37 } nut_priv_tt;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
38
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
39 static size_t mp_read(void * h, size_t len, uint8_t * buf) {
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_eof(stream)) return 0;
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
43 //len = MIN(len, 5);
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
44
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
45 return stream_read(stream, buf, len);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
46 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
47
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
48 static int mp_eof(void * h) {
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
49 stream_t * stream = (stream_t*)h;
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
50 if(stream_eof(stream)) return 1;
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
51 return 0;
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
52 }
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
53
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
54 static off_t mp_seek(void * h, long long pos, int whence) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
55 stream_t * stream = (stream_t*)h;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
56
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
57 if (stream->end_pos < stream_tell(stream))
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
58 stream->end_pos = stream_tell(stream);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
59
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
60 if (whence == SEEK_CUR) pos += stream_tell(stream);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
61 else if (whence == SEEK_END) pos += stream->end_pos;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
62 else if (whence != SEEK_SET) return -1;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
63
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
64 if (pos < stream->end_pos && stream->eof) stream_reset(stream);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
65 if (stream_seek(stream, pos) == 0) return -1;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
66
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
67 return pos;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
68 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
69
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
70 #define ID_STRING "nut/multimedia container"
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
71 #define ID_LENGTH (strlen(ID_STRING) + 1)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
72
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
73 static int nut_check_file(demuxer_t * demuxer) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
74 uint8_t buf[ID_LENGTH];
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
75
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
76 if (stream_read(demuxer->stream, buf, ID_LENGTH) != ID_LENGTH) return 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
77
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
78 if (memcmp(buf, ID_STRING, ID_LENGTH)) return 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
79
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
80 stream_seek(demuxer->stream, 0);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
81 return DEMUXER_TYPE_NUT;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
82 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
83
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
84 static demuxer_t * demux_open_nut(demuxer_t * demuxer) {
28099
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
85 nut_demuxer_opts_tt dopts = {
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
86 .input = {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
87 .priv = demuxer->stream,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
88 .seek = mp_seek,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
89 .read = mp_read,
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
90 .eof = mp_eof,
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
91 .file_pos = stream_tell(demuxer->stream),
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
92 },
19957
41153a5b5f8e sync to new libnut
ods15
parents: 19861
diff changeset
93 .alloc = { .malloc = NULL },
20909
fd91718e6c76 update to libnut, add cache_syncpoints
ods15
parents: 20893
diff changeset
94 .read_index = index_mode,
fd91718e6c76 update to libnut, add cache_syncpoints
ods15
parents: 20893
diff changeset
95 .cache_syncpoints = 1,
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
96 };
28099
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
97 nut_priv_tt * priv = demuxer->priv = calloc(1, sizeof(nut_priv_tt));
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
98 nut_context_tt * nut = priv->nut = nut_demuxer_init(&dopts);
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
99 nut_stream_header_tt * s;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
100 int ret;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
101 int i;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
102
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
103 while ((ret = nut_read_headers(nut, &s, NULL)) == NUT_ERR_EAGAIN);
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
104 if (ret) {
20938
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
105 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
106 return NULL;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
107 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
108
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
109 priv->s = s;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
110
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
111 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
112 case NUT_AUDIO_CLASS: {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
113 WAVEFORMATEX *wf =
32121
d332ea379205 Replace sizeof(WAVEFORMATEX) occurrences.
reimar
parents: 31609
diff changeset
114 calloc(sizeof(*wf) +
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
115 s[i].codec_specific_len, 1);
31609
cd81fce1f010 Make the stream language an argument to the stream creation function
reimar
parents: 29238
diff changeset
116 sh_audio_t* sh_audio = new_sh_audio(demuxer, i, NULL);
28101
231f008859b9 Warning fixes for demux_nut
ods15
parents: 28100
diff changeset
117 int j;
23010
74efb0fa8a0b with -identify show audio and video id; patch by Andrew Savchenko (Bircoph list ru)
nicodvb
parents: 22605
diff changeset
118 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_AudioID, "nut", i);
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
119
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
120 sh_audio->wf= wf; sh_audio->ds = demuxer->audio;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
121 sh_audio->audio.dwSampleSize = 0; // FIXME
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
122 sh_audio->audio.dwScale = s[i].time_base.num;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
123 sh_audio->audio.dwRate = s[i].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
124 sh_audio->format = 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
125 for (j = 0; j < s[i].fourcc_len && j < 4; j++)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
126 sh_audio->format |= s[i].fourcc[j]<<(j*8);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
127 sh_audio->channels = s[i].channel_count;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
128 sh_audio->samplerate =
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
129 s[i].samplerate_num / s[i].samplerate_denom;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
130 sh_audio->i_bps = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
131
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
132 wf->wFormatTag = sh_audio->format;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
133 wf->nChannels = s[i].channel_count;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
134 wf->nSamplesPerSec =
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
135 s[i].samplerate_num / s[i].samplerate_denom;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
136 wf->nAvgBytesPerSec = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
137 wf->nBlockAlign = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
138 wf->wBitsPerSample = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
139 wf->cbSize = s[i].codec_specific_len;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
140 if (s[i].codec_specific_len)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
141 memcpy(wf + 1, s[i].codec_specific,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
142 s[i].codec_specific_len);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
143
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
144 demuxer->audio->id = i;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
145 demuxer->audio->sh= demuxer->a_streams[i];
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
146 break;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
147 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
148 case NUT_VIDEO_CLASS: {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
149 BITMAPINFOHEADER * bih =
32123
a86413775fbe Replace sizeof(BITMAPINFOHEADER)
reimar
parents: 32121
diff changeset
150 calloc(sizeof(*bih) +
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
151 s[i].codec_specific_len, 1);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
152 sh_video_t * sh_video = new_sh_video(demuxer, i);
28101
231f008859b9 Warning fixes for demux_nut
ods15
parents: 28100
diff changeset
153 int j;
23010
74efb0fa8a0b with -identify show audio and video id; patch by Andrew Savchenko (Bircoph list ru)
nicodvb
parents: 22605
diff changeset
154 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_VideoID, "nut", i);
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
155
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
156 sh_video->bih = bih;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
157 sh_video->ds = demuxer->video;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
158 sh_video->disp_w = s[i].width;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
159 sh_video->disp_h = s[i].height;
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
160 sh_video->video.dwScale = s[i].time_base.num;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
161 sh_video->video.dwRate = s[i].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
162
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
163 sh_video->fps = sh_video->video.dwRate/
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
164 (float)sh_video->video.dwScale;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
165 sh_video->frametime = 1./sh_video->fps;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
166 sh_video->format = 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
167 for (j = 0; j < s[i].fourcc_len && j < 4; j++)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
168 sh_video->format |= s[i].fourcc[j]<<(j*8);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
169 if (!s[i].sample_height) sh_video->aspect = 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
170 else sh_video->aspect =
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
171 s[i].sample_width / (float)s[i].sample_height;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
172 sh_video->i_bps = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
173
32123
a86413775fbe Replace sizeof(BITMAPINFOHEADER)
reimar
parents: 32121
diff changeset
174 bih->biSize = sizeof(*bih) +
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
175 s[i].codec_specific_len;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
176 bih->biWidth = s[i].width;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
177 bih->biHeight = s[i].height;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
178 bih->biBitCount = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
179 bih->biSizeImage = 0; // FIXME
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
180 bih->biCompression = sh_video->format;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
181
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
182 if (s[i].codec_specific_len)
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
183 memcpy(bih + 1, s[i].codec_specific,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
184 s[i].codec_specific_len);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
185
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
186 demuxer->video->id = i;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
187 demuxer->video->sh = demuxer->v_streams[i];
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
188 break;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
189 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
190 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
191
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
192 return demuxer;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
193 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
194
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
195 static int demux_nut_fill_buffer(demuxer_t * demuxer, demux_stream_t * dsds) {
28099
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
196 nut_priv_tt * priv = demuxer->priv;
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
197 nut_context_tt * nut = priv->nut;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
198 demux_packet_t *dp;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
199 demux_stream_t *ds;
28099
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
200 nut_packet_tt pd;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
201 int ret;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
202 double pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
203
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
204 demuxer->filepos = stream_tell(demuxer->stream);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
205 if (stream_eof(demuxer->stream)) return 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
206
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
207 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
208 if (ret) {
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
209 if (ret != NUT_ERR_EOF)
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
210 mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n",
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
211 nut_error(ret));
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
212 return 0; // fatal error
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
213 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
214
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
215 pts = (double)pd.pts * priv->s[pd.stream].time_base.num /
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
216 priv->s[pd.stream].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
217
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
218 if (pd.stream == demuxer->audio->id) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
219 ds = demuxer->audio;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
220 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
221 else if (pd.stream == demuxer->video->id) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
222 ds = demuxer->video;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
223 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
224 else {
20926
623e0adc71a2 update to libnut, no nut_skip_packet()
ods15
parents: 20925
diff changeset
225 uint8_t buf[pd.len];
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
226 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
227 if (ret) {
19958
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
228 mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n",
20938
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
229 nut_error(ret));
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
230 return 0; // fatal error
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
231 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
232 return 1;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
233 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
234
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
235 if (pd.stream == 0) priv->last_pts = pd.pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
236
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
237 dp = new_demux_packet(pd.len);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
238
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
239 dp->pts = pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
240
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
241 dp->pos = demuxer->filepos;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
242 dp->flags= (pd.flags & NUT_FLAG_KEY) ? 0x10 : 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
243
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
244 {int len = pd.len;
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
245 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
246 }
20938
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
247 if (ret) {
19958
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
248 mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n",
20938
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
249 nut_error(ret));
2f29235bcc69 update to libnut API, non-negative errors
ods15
parents: 20926
diff changeset
250 return 0; // fatal error
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
251 }
19958
e50391b26740 simplifications, any error from libnut is fatal
ods15
parents: 19957
diff changeset
252
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
253 ds_add_packet(ds, dp); // append packet to DS stream
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
254 return 1;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
255 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
256
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
257 static void demux_seek_nut(demuxer_t * demuxer, float time_pos, float audio_delay, int flags) {
28099
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
258 nut_context_tt * nut = ((nut_priv_tt*)demuxer->priv)->nut;
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
259 nut_priv_tt * priv = demuxer->priv;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
260 int nutflags = 0;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
261 int ret;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
262 const int tmp[] = { 0, -1 };
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
263
25883
baf32110d3fc Use defines to give names to the different seek flags.
reimar
parents: 25707
diff changeset
264 if (!(flags & SEEK_ABSOLUTE)) {
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
265 nutflags |= 1; // relative
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
266 if (time_pos > 0) nutflags |= 2; // forwards
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
267 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
268
25883
baf32110d3fc Use defines to give names to the different seek flags.
reimar
parents: 25707
diff changeset
269 if (flags & SEEK_FACTOR)
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
270 time_pos *= priv->s[0].max_pts *
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
271 (double)priv->s[0].time_base.num /
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
272 priv->s[0].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
273
21022
fbf3f8cd0bf6 Add disabled EAGAIN testing code for libnut
ods15
parents: 21011
diff changeset
274 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
275 priv->last_pts = -1;
20971
e243a3de18c2 missed piece in update to libnut API - non negative errors
ods15
parents: 20938
diff changeset
276 if (ret) mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n", nut_error(ret));
21023
f5180197d7ad fix demux_nut to give proper (estimate) of percent position after a seek
ods15
parents: 21022
diff changeset
277 demuxer->filepos = stream_tell(demuxer->stream);
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
278 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
279
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
280 static int demux_control_nut(demuxer_t * demuxer, int cmd, void * arg) {
28099
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
281 nut_priv_tt * priv = demuxer->priv;
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
282 switch (cmd) {
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
283 case DEMUXER_CTRL_GET_TIME_LENGTH:
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
284 *((double *)arg) = priv->s[0].max_pts *
21723
a804f969af97 Sync to libnut, nom->num
ods15
parents: 21023
diff changeset
285 (double)priv->s[0].time_base.num /
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
286 priv->s[0].time_base.den;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
287 return DEMUXER_CTRL_OK;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
288 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
289 if (priv->s[0].max_pts == 0 || priv->last_pts == -1)
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
290 return DEMUXER_CTRL_DONTKNOW;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
291 *((int *)arg) = priv->last_pts * 100 /
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
292 (double)priv->s[0].max_pts;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
293 return DEMUXER_CTRL_OK;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
294 default:
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
295 return DEMUXER_CTRL_NOTIMPL;
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
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
299 static void demux_close_nut(demuxer_t *demuxer) {
28099
3d88e7067d06 Rename typedefs in demux_nut to _tt instead of _t, sync to new libnut API
ods15
parents: 27730
diff changeset
300 nut_priv_tt * priv = demuxer->priv;
21011
b3fbda23e570 move demux_nut priv calloc to init() instead of check_file()
ods15
parents: 20971
diff changeset
301 if (!priv) return;
20925
74b8d7cf4edb update to libnut API, don't free the streams
ods15
parents: 20909
diff changeset
302 nut_demuxer_uninit(priv->nut);
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
303 free(demuxer->priv);
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
304 demuxer->priv = NULL;
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
305 }
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
306
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
307
25707
d4fe6e23283e Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents: 24118
diff changeset
308 const demuxer_desc_t demuxer_desc_nut = {
19861
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
309 "NUT demuxer",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
310 "nut",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
311 "libnut",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
312 "Oded Shimon (ods15)",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
313 "NUT demuxer, requires libnut",
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
314 DEMUXER_TYPE_NUT,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
315 1, // safe check demuxer
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
316 nut_check_file,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
317 demux_nut_fill_buffer,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
318 demux_open_nut,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
319 demux_close_nut,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
320 demux_seek_nut,
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
321 demux_control_nut
b251bca5820c Add demux_nut to MPlayer repo
ods15
parents:
diff changeset
322 };