annotate libnut.c @ 1562:61df6b5d52d3 libavformat

use amf_get_string()
author michael
date Sun, 10 Dec 2006 17:38:16 +0000
parents 518d9cecef02
children 72cb68e511e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1482
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
1 #include "avformat.h"
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
2 #include "riff.h"
1499
88c11d433ffb update to libnut API, rename nut.h->libnut.h
ods15
parents: 1487
diff changeset
3 #include <libnut.h>
1482
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
4
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
5 #define ID_STRING "nut/multimedia container"
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
6 #define ID_LENGTH (strlen(ID_STRING) + 1)
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
7
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
8 typedef struct {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
9 nut_context_t * nut;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
10 nut_stream_header_t * s;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
11 } NUTContext;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
12
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
13 static const CodecTag nut_tags[] = {
1525
518d9cecef02 change mpeg4 fourcc from "mp4s" to "mp4v"
ods15
parents: 1524
diff changeset
14 { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
1482
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
15 { CODEC_ID_MP3, MKTAG('m', 'p', '3', ' ') },
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
16 { CODEC_ID_VORBIS, MKTAG('v', 'r', 'b', 's') },
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
17 { 0, 0 },
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
18 };
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
19
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
20 #ifdef CONFIG_MUXERS
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
21 static int av_write(void * h, size_t len, const uint8_t * buf) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
22 ByteIOContext * bc = h;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
23 put_buffer(bc, buf, len);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
24 //put_flush_packet(bc);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
25 return len;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
26 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
27
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
28 static int nut_write_header(AVFormatContext * avf) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
29 NUTContext * priv = avf->priv_data;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
30 ByteIOContext * bc = &avf->pb;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
31 nut_muxer_opts_t mopts = {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
32 .output = {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
33 .priv = bc,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
34 .write = av_write,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
35 },
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
36 .alloc = { av_malloc, av_realloc, av_free },
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
37 .write_index = 1,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
38 .realtime_stream = 0,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
39 .max_distance = 32768,
1524
bffedde11b4f update to libnut, use framecode table generator
ods15
parents: 1523
diff changeset
40 .fti = NULL,
1482
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
41 };
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
42 nut_stream_header_t * s;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
43 int i;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
44
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
45 priv->s = s = av_mallocz((avf->nb_streams + 1) * sizeof*s);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
46
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
47 for (i = 0; i < avf->nb_streams; i++) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
48 AVCodecContext * codec = avf->streams[i]->codec;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
49 int j;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
50 int fourcc = 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
51 int nom, denom, ssize;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
52
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
53 s[i].type = codec->codec_type == CODEC_TYPE_VIDEO ? NUT_VIDEO_CLASS : NUT_AUDIO_CLASS;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
54
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
55 if (codec->codec_tag) fourcc = codec->codec_tag;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
56 else fourcc = codec_get_tag(nut_tags, codec->codec_id);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
57
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
58 if (!fourcc) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
59 if (codec->codec_type == CODEC_TYPE_VIDEO) fourcc = codec_get_bmp_tag(codec->codec_id);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
60 if (codec->codec_type == CODEC_TYPE_AUDIO) fourcc = codec_get_wav_tag(codec->codec_id);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
61 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
62
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
63 s[i].fourcc_len = 4;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
64 s[i].fourcc = av_malloc(s[i].fourcc_len);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
65 for (j = 0; j < s[i].fourcc_len; j++) s[i].fourcc[j] = (fourcc >> (j*8)) & 0xFF;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
66
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
67 ff_parse_specific_params(codec, &nom, &ssize, &denom);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
68 av_set_pts_info(avf->streams[i], 60, denom, nom);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
69
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
70 s[i].time_base.nom = denom;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
71 s[i].time_base.den = nom;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
72
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
73 s[i].fixed_fps = 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
74 s[i].decode_delay = codec->has_b_frames;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
75 s[i].codec_specific_len = codec->extradata_size;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
76 s[i].codec_specific = codec->extradata;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
77
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
78 if (codec->codec_type == CODEC_TYPE_VIDEO) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
79 s[i].width = codec->width;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
80 s[i].height = codec->height;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
81 s[i].sample_width = 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
82 s[i].sample_height = 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
83 s[i].colorspace_type = 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
84 } else {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
85 s[i].samplerate_nom = codec->sample_rate;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
86 s[i].samplerate_denom = 1;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
87 s[i].channel_count = codec->channels;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
88 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
89 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
90
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
91 s[avf->nb_streams].type = -1;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
92 priv->nut = nut_muxer_init(&mopts, s, NULL);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
93
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
94 return 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
95 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
96
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
97 static int nut_write_packet(AVFormatContext * avf, AVPacket * pkt) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
98 NUTContext * priv = avf->priv_data;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
99 nut_packet_t p;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
100
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
101 p.len = pkt->size;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
102 p.stream = pkt->stream_index;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
103 p.pts = pkt->pts;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
104 p.flags = pkt->flags & PKT_FLAG_KEY ? NUT_FLAG_KEY : 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
105 p.next_pts = 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
106
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
107 nut_write_frame_reorder(priv->nut, &p, pkt->data);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
108
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
109 return 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
110 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
111
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
112 static int nut_write_trailer(AVFormatContext * avf) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
113 ByteIOContext * bc = &avf->pb;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
114 NUTContext * priv = avf->priv_data;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
115 int i;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
116
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
117 nut_muxer_uninit_reorder(priv->nut);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
118 put_flush_packet(bc);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
119
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
120 for(i = 0; priv->s[i].type != -1; i++ ) av_freep(&priv->s[i].fourcc);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
121 av_freep(&priv->s);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
122
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
123 return 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
124 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
125
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
126 AVOutputFormat nut_muxer = {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
127 "nut",
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
128 "nut format",
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
129 "video/x-nut",
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
130 "nut",
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
131 sizeof(NUTContext),
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
132 CODEC_ID_VORBIS,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
133 CODEC_ID_MPEG4,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
134 nut_write_header,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
135 nut_write_packet,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
136 nut_write_trailer,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
137 .flags = AVFMT_GLOBALHEADER,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
138 };
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
139 #endif //CONFIG_MUXERS
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
140
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
141 static int nut_probe(AVProbeData *p) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
142 if (p->buf_size >= ID_LENGTH && !memcmp(p->buf, ID_STRING, ID_LENGTH)) return AVPROBE_SCORE_MAX;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
143
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
144 return 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
145 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
146
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
147 static size_t av_read(void * h, size_t len, uint8_t * buf) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
148 ByteIOContext * bc = h;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
149 return get_buffer(bc, buf, len);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
150 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
151
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
152 static off_t av_seek(void * h, long long pos, int whence) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
153 ByteIOContext * bc = h;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
154 if (whence == SEEK_END) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
155 pos = url_fsize(bc) + pos;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
156 whence = SEEK_SET;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
157 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
158 return url_fseek(bc, pos, whence);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
159 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
160
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
161 static int nut_read_header(AVFormatContext * avf, AVFormatParameters * ap) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
162 NUTContext * priv = avf->priv_data;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
163 ByteIOContext * bc = &avf->pb;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
164 nut_demuxer_opts_t dopts = {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
165 .input = {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
166 .priv = bc,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
167 .seek = av_seek,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
168 .read = av_read,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
169 .eof = NULL,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
170 .file_pos = 0,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
171 },
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
172 .alloc = { av_malloc, av_realloc, av_free },
1505
5b225077f098 update to libnut, add cache_syncpoints
ods15
parents: 1499
diff changeset
173 .read_index = 1,
5b225077f098 update to libnut, add cache_syncpoints
ods15
parents: 1499
diff changeset
174 .cache_syncpoints = 1,
1482
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
175 };
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
176 nut_context_t * nut = priv->nut = nut_demuxer_init(&dopts);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
177 nut_stream_header_t * s;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
178 int ret, i;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
179
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
180 if ((ret = nut_read_headers(nut, &s, NULL))) {
1513
7d1a53de280a Update to libnut API, non-negative errors
ods15
parents: 1512
diff changeset
181 av_log(avf, AV_LOG_ERROR, " NUT error: %s\n", nut_error(ret));
1482
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
182 nut_demuxer_uninit(nut);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
183 return -1;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
184 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
185
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
186 priv->s = s;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
187
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
188 for (i = 0; s[i].type != -1 && i < 2; i++) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
189 AVStream * st = av_new_stream(avf, i);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
190 int j;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
191
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
192 for (j = 0; j < s[i].fourcc_len && j < 8; j++) st->codec->codec_tag |= s[i].fourcc[j]<<(j*8);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
193
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
194 st->codec->has_b_frames = s[i].decode_delay;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
195
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
196 st->codec->extradata_size = s[i].codec_specific_len;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
197 if (st->codec->extradata_size) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
198 st->codec->extradata = av_mallocz(st->codec->extradata_size);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
199 memcpy(st->codec->extradata, s[i].codec_specific, st->codec->extradata_size);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
200 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
201
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
202 av_set_pts_info(avf->streams[i], 60, s[i].time_base.nom, s[i].time_base.den);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
203 st->start_time = 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
204 st->duration = s[i].max_pts;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
205
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
206 st->codec->codec_id = codec_get_id(nut_tags, st->codec->codec_tag);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
207
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
208 switch(s[i].type) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
209 case NUT_AUDIO_CLASS:
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
210 st->codec->codec_type = CODEC_TYPE_AUDIO;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
211 if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = codec_get_wav_id(st->codec->codec_tag);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
212
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
213 st->codec->channels = s[i].channel_count;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
214 st->codec->sample_rate = s[i].samplerate_nom / s[i].samplerate_denom;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
215 break;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
216 case NUT_VIDEO_CLASS:
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
217 st->codec->codec_type = CODEC_TYPE_VIDEO;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
218 if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = codec_get_bmp_id(st->codec->codec_tag);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
219
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
220 st->codec->width = s[i].width;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
221 st->codec->height = s[i].height;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
222 st->codec->sample_aspect_ratio.num = s[i].sample_width;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
223 st->codec->sample_aspect_ratio.den = s[i].sample_height;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
224 break;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
225 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
226 if (st->codec->codec_id == CODEC_ID_NONE) av_log(avf, AV_LOG_ERROR, "Unknown codec?!\n");
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
227 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
228
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
229 return 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
230 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
231
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
232 static int nut_read_packet(AVFormatContext * avf, AVPacket * pkt) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
233 NUTContext * priv = avf->priv_data;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
234 nut_packet_t pd;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
235 int ret;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
236
1513
7d1a53de280a Update to libnut API, non-negative errors
ods15
parents: 1512
diff changeset
237 ret = nut_read_next_packet(priv->nut, &pd);
1482
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
238
1513
7d1a53de280a Update to libnut API, non-negative errors
ods15
parents: 1512
diff changeset
239 if (ret || av_new_packet(pkt, pd.len) < 0) {
7d1a53de280a Update to libnut API, non-negative errors
ods15
parents: 1512
diff changeset
240 if (ret != NUT_ERR_EOF)
7d1a53de280a Update to libnut API, non-negative errors
ods15
parents: 1512
diff changeset
241 av_log(avf, AV_LOG_ERROR, " NUT error: %s\n", nut_error(ret));
7d1a53de280a Update to libnut API, non-negative errors
ods15
parents: 1512
diff changeset
242 return -1;
7d1a53de280a Update to libnut API, non-negative errors
ods15
parents: 1512
diff changeset
243 }
1482
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
244
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
245 if (pd.flags & NUT_FLAG_KEY) pkt->flags |= PKT_FLAG_KEY;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
246 pkt->pts = pd.pts;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
247 pkt->stream_index = pd.stream;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
248 pkt->pos = url_ftell(&avf->pb);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
249
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
250 ret = nut_read_frame(priv->nut, &pd.len, pkt->data);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
251
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
252 return ret;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
253 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
254
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
255 static int nut_read_seek(AVFormatContext * avf, int stream_index, int64_t target_ts, int flags) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
256 NUTContext * priv = avf->priv_data;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
257 int active_streams[] = { stream_index, -1 };
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
258 double time_pos = target_ts * priv->s[stream_index].time_base.nom / (double)priv->s[stream_index].time_base.den;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
259
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
260 if (nut_seek(priv->nut, time_pos, 2*!(flags & AVSEEK_FLAG_BACKWARD), active_streams)) return -1;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
261
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
262 return 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
263 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
264
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
265 static int nut_read_close(AVFormatContext *s) {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
266 NUTContext * priv = s->priv_data;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
267
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
268 nut_demuxer_uninit(priv->nut);
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
269
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
270 return 0;
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
271 }
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
272
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
273 AVInputFormat nut_demuxer = {
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
274 "nut",
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
275 "nut format",
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
276 sizeof(NUTContext),
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
277 nut_probe,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
278 nut_read_header,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
279 nut_read_packet,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
280 nut_read_close,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
281 nut_read_seek,
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
282 .extensions = "nut",
617beb4c6247 Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff changeset
283 };