Revision f956e129

View differences:

configure
31 31
  echo "  --incdir=DIR             install includes in DIR [PREFIX/include/ffmpeg]"
32 32
  echo "  --mandir=DIR             install man page in DIR [PREFIX/man]"
33 33
  echo "  --enable-mp3lame         enable MP3 encoding via libmp3lame [default=no]"
34
  echo "  --enable-libnut          enable NUT support via libnut [default=no]"
34 35
  echo "  --enable-libogg          enable Ogg support via libogg [default=no]"
35 36
  echo "  --enable-vorbis          enable Vorbis support via libvorbis [default=no]"
36 37
  echo "  --enable-faad            enable FAAD support via libfaad [default=no]"
......
422 423
zlib="yes"
423 424
libgsm="no"
424 425
mp3lame="no"
426
libnut="no"
425 427
libogg="no"
426 428
vorbis="no"
427 429
faad="no"
......
771 773
  ;;
772 774
  --enable-mp3lame) mp3lame="yes"
773 775
  ;;
776
  --enable-libnut) libnut="yes"
777
  ;;
774 778
  --enable-libogg) libogg="yes"
775 779
    pkg_requires="$pkg_requires ogg >= 1.1"
776 780
  ;;
......
1321 1325
enabled mp3lame && require LAME lame/lame.h lame_init -lmp3lame -lm
1322 1326
enabled vorbis  && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbis -lvorbisenc -logg
1323 1327
enabled libogg  && require libogg ogg/ogg.h ogg_sync_init -logg
1328
enabled libnut  && require libnut nut.h nut_demuxer_init -lnut
1324 1329
enabled xvid    && require XviD xvid.h xvid_global -lxvidcore
1325 1330
enabled x264    && require x264 x264.h x264_encoder_open -lx264
1326 1331
enabled dc1394  && require libdc1394 libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394
......
1599 1604
echo "zlib enabled     $zlib"
1600 1605
echo "libgsm enabled   $libgsm"
1601 1606
echo "mp3lame enabled  $mp3lame"
1607
echo "libnut enabled   $libnut"
1602 1608
echo "libogg enabled   $libogg"
1603 1609
echo "Vorbis enabled   $vorbis"
1604 1610
echo "FAAD enabled     $faad"
......
1999 2005
  echo "CONFIG_MP3LAME=yes" >> config.mak
2000 2006
fi
2001 2007

  
2008
if test "$libnut" = "yes" ; then
2009
  echo "#define CONFIG_LIBNUT 1" >> $TMPH
2010
  echo "CONFIG_LIBNUT=yes" >> config.mak
2011
fi
2012

  
2002 2013
if test "$libogg" = "yes" ; then
2003 2014
  echo "#define CONFIG_LIBOGG 1" >> $TMPH
2004 2015
  echo "CONFIG_LIBOGG=yes" >> config.mak
libavformat/Makefile
73 73
OBJS-$(CONFIG_MPJPEG_MUXER)              += mpjpeg.o
74 74
OBJS-$(CONFIG_MXF_DEMUXER)               += mxf.o
75 75
OBJS-$(CONFIG_NSV_DEMUXER)               += nsvdec.o riff.o
76
OBJS-$(CONFIG_NUT_DEMUXER)               += nutdec.o riff.o
77
#OBJS-$(CONFIG_NUT_MUXER)                 += nutenc.o riff.o
78 76
OBJS-$(CONFIG_NUV_DEMUXER)               += nuv.o riff.o
79 77
OBJS-$(CONFIG_OGG_DEMUXER)               += ogg2.o           \
80 78
                                            oggparsevorbis.o \
......
176 174
endif
177 175
endif
178 176

  
177
ifeq ($(CONFIG_LIBNUT),yes)
178
OBJS-$(CONFIG_NUT_DEMUXER)               += libnut.o riff.o
179
OBJS-$(CONFIG_NUT_MUXER)                 += libnut.o riff.o
180
else
181
OBJS-$(CONFIG_NUT_DEMUXER)               += nutdec.o riff.o
182
#OBJS-$(CONFIG_NUT_MUXER)                 += nutenc.o riff.o
183
endif
184

  
179 185
ifeq ($(CONFIG_LIBOGG),yes)
180 186
OBJS-$(CONFIG_OGG_MUXER)                 += ogg.o
181 187
endif
libavformat/libnut.c
1
#include "avformat.h"
2
#include "riff.h"
3
#include "nut.h"
4

  
5
#define ID_STRING "nut/multimedia container"
6
#define ID_LENGTH (strlen(ID_STRING) + 1)
7

  
8
typedef struct {
9
    nut_context_t * nut;
10
    nut_stream_header_t * s;
11
} NUTContext;
12

  
13
static const CodecTag nut_tags[] = {
14
    { CODEC_ID_MPEG4,  MKTAG('m', 'p', '4', 's') },
15
    { CODEC_ID_MP3,    MKTAG('m', 'p', '3', ' ') },
16
    { CODEC_ID_VORBIS, MKTAG('v', 'r', 'b', 's') },
17
    { 0, 0 },
18
};
19

  
20
#ifdef CONFIG_MUXERS
21
frame_table_input_t ft_default[] = {
22
    // There must be atleast this safety net:
23
    //{ 4128,      3,   0,   1,      0,    0,     0 },
24
    //{ flag, fields, pts, mul, stream, size, count }
25
      { 8192,      0,   0,   1,      0,    0,     0 }, // invalid 0x00
26
      {   56,      0,   0,   1,      0,    0,     0 }, // safety net non key frame
27
      {   56,      0,   0,   1,      0,    0,     0 }, // safety net key frame
28
      { 4128,      0,   0,   1,      0,    0,     0 }, // one more safety net
29
      {   27,      0,   0,   1,      0,    0,     0 }, // EOR frame
30
      {    1,      4,   1, 337,      1,  336,     0 }, // used 82427 times
31
      {    1,      4,   1, 385,      1,  384,     0 }, // used 56044 times
32
      {    0,      4,   2,   7,      0,    6,     0 }, // used 20993 times
33
      {    0,      4,   1,   7,      0,    6,     0 }, // used 10398 times
34
      {    1,      4,   1, 481,      1,  480,     0 }, // used 3527 times
35
      {    1,      4,   1, 289,      1,  288,     0 }, // used 2042 times
36
      {    1,      4,   1, 577,      1,  576,     0 }, // used 1480 times
37
      {    1,      4,   1, 673,      1,  672,     0 }, // used 862 times
38
      {    1,      4,   1, 769,      1,  768,     0 }, // used 433 times
39
      {    1,      4,   1, 961,      1,  960,     0 }, // used 191 times
40
      {   32,      3,   2, 101,      0,    0,     0 }, // "1.2.0" => 14187
41
      {   32,      3,  -1,  40,      0,    0,     0 }, // "1.-1.0" => 5707
42
      {   32,      3,   1,  81,      0,    0,     0 }, // "1.1.0" => 11159
43
      {   33,      3,   1,  11,      0,    0,     0 }, // "1.1.1" => 1409
44
      {  105,      3,   0,   6,      0,    0,     0 }, // checksum for video
45
      { 8192,      2,   0,   1,      0,    0,     0 }, // invalid 0xFF
46
      {   -1,      0,   0,   0,      0,    0,     0 }, // end
47
};
48

  
49
static int av_write(void * h, size_t len, const uint8_t * buf) {
50
    ByteIOContext * bc = h;
51
    put_buffer(bc, buf, len);
52
    //put_flush_packet(bc);
53
    return len;
54
}
55

  
56
static int nut_write_header(AVFormatContext * avf) {
57
    NUTContext * priv = avf->priv_data;
58
    ByteIOContext * bc = &avf->pb;
59
    nut_muxer_opts_t mopts = {
60
        .output = {
61
            .priv = bc,
62
            .write = av_write,
63
        },
64
        .alloc = { av_malloc, av_realloc, av_free },
65
        .write_index = 1,
66
        .realtime_stream = 0,
67
        .max_distance = 32768,
68
        .fti = ft_default
69
    };
70
    nut_stream_header_t * s;
71
    int i;
72

  
73
    priv->s = s = av_mallocz((avf->nb_streams + 1) * sizeof*s);
74

  
75
    for (i = 0; i < avf->nb_streams; i++) {
76
        AVCodecContext * codec = avf->streams[i]->codec;
77
        int j;
78
        int fourcc = 0;
79
        int nom, denom, ssize;
80

  
81
        s[i].type = codec->codec_type == CODEC_TYPE_VIDEO ? NUT_VIDEO_CLASS : NUT_AUDIO_CLASS;
82

  
83
        if (codec->codec_tag) fourcc = codec->codec_tag;
84
        else fourcc = codec_get_tag(nut_tags, codec->codec_id);
85

  
86
        if (!fourcc) {
87
            if (codec->codec_type == CODEC_TYPE_VIDEO) fourcc = codec_get_bmp_tag(codec->codec_id);
88
            if (codec->codec_type == CODEC_TYPE_AUDIO) fourcc = codec_get_wav_tag(codec->codec_id);
89
        }
90

  
91
        s[i].fourcc_len = 4;
92
        s[i].fourcc = av_malloc(s[i].fourcc_len);
93
        for (j = 0; j < s[i].fourcc_len; j++) s[i].fourcc[j] = (fourcc >> (j*8)) & 0xFF;
94

  
95
        ff_parse_specific_params(codec, &nom, &ssize, &denom);
96
        av_set_pts_info(avf->streams[i], 60, denom, nom);
97

  
98
        s[i].time_base.nom = denom;
99
        s[i].time_base.den = nom;
100

  
101
        s[i].fixed_fps = 0;
102
        s[i].decode_delay = codec->has_b_frames;
103
        s[i].codec_specific_len = codec->extradata_size;
104
        s[i].codec_specific = codec->extradata;
105

  
106
        if (codec->codec_type == CODEC_TYPE_VIDEO) {
107
            s[i].width = codec->width;
108
            s[i].height = codec->height;
109
            s[i].sample_width = 0;
110
            s[i].sample_height = 0;
111
            s[i].colorspace_type = 0;
112
        } else {
113
            s[i].samplerate_nom = codec->sample_rate;
114
            s[i].samplerate_denom = 1;
115
            s[i].channel_count = codec->channels;
116
        }
117
    }
118

  
119
    s[avf->nb_streams].type = -1;
120
    priv->nut = nut_muxer_init(&mopts, s, NULL);
121

  
122
    return 0;
123
}
124

  
125
static int nut_write_packet(AVFormatContext * avf, AVPacket * pkt) {
126
    NUTContext * priv = avf->priv_data;
127
    nut_packet_t p;
128

  
129
    p.len = pkt->size;
130
    p.stream = pkt->stream_index;
131
    p.pts = pkt->pts;
132
    p.flags = pkt->flags & PKT_FLAG_KEY ? NUT_FLAG_KEY : 0;
133
    p.next_pts = 0;
134

  
135
    nut_write_frame_reorder(priv->nut, &p, pkt->data);
136

  
137
    return 0;
138
}
139

  
140
static int nut_write_trailer(AVFormatContext * avf) {
141
    ByteIOContext * bc = &avf->pb;
142
    NUTContext * priv = avf->priv_data;
143
    int i;
144

  
145
    nut_muxer_uninit_reorder(priv->nut);
146
    put_flush_packet(bc);
147

  
148
    for(i = 0; priv->s[i].type != -1; i++ ) av_freep(&priv->s[i].fourcc);
149
    av_freep(&priv->s);
150

  
151
    return 0;
152
}
153

  
154
AVOutputFormat nut_muxer = {
155
    "nut",
156
    "nut format",
157
    "video/x-nut",
158
    "nut",
159
    sizeof(NUTContext),
160
    CODEC_ID_VORBIS,
161
    CODEC_ID_MPEG4,
162
    nut_write_header,
163
    nut_write_packet,
164
    nut_write_trailer,
165
    .flags = AVFMT_GLOBALHEADER,
166
};
167
#endif //CONFIG_MUXERS
168

  
169
static int nut_probe(AVProbeData *p) {
170
    if (p->buf_size >= ID_LENGTH && !memcmp(p->buf, ID_STRING, ID_LENGTH)) return AVPROBE_SCORE_MAX;
171

  
172
    return 0;
173
}
174

  
175
static size_t av_read(void * h, size_t len, uint8_t * buf) {
176
    ByteIOContext * bc = h;
177
    return get_buffer(bc, buf, len);
178
}
179

  
180
static off_t av_seek(void * h, long long pos, int whence) {
181
    ByteIOContext * bc = h;
182
    if (whence == SEEK_END) {
183
        pos = url_fsize(bc) + pos;
184
        whence = SEEK_SET;
185
    }
186
    return url_fseek(bc, pos, whence);
187
}
188

  
189
static int nut_read_header(AVFormatContext * avf, AVFormatParameters * ap) {
190
    NUTContext * priv = avf->priv_data;
191
    ByteIOContext * bc = &avf->pb;
192
    nut_demuxer_opts_t dopts = {
193
        .input = {
194
            .priv = bc,
195
            .seek = av_seek,
196
            .read = av_read,
197
            .eof = NULL,
198
            .file_pos = 0,
199
        },
200
        .alloc = { av_malloc, av_realloc, av_free },
201
        .read_index = 1
202
    };
203
    nut_context_t * nut = priv->nut = nut_demuxer_init(&dopts);
204
    nut_stream_header_t * s;
205
    int ret, i;
206

  
207
    if ((ret = nut_read_headers(nut, &s, NULL))) {
208
        if (ret < 0) av_log(avf, AV_LOG_ERROR, " NUT error: %s\n", nut_error(-ret));
209
        nut_demuxer_uninit(nut);
210
        return -1;
211
    }
212

  
213
    priv->s = s;
214

  
215
    for (i = 0; s[i].type != -1 && i < 2; i++) {
216
        AVStream * st = av_new_stream(avf, i);
217
        int j;
218

  
219
        for (j = 0; j < s[i].fourcc_len && j < 8; j++) st->codec->codec_tag |= s[i].fourcc[j]<<(j*8);
220

  
221
        st->codec->has_b_frames = s[i].decode_delay;
222

  
223
        st->codec->extradata_size = s[i].codec_specific_len;
224
        if (st->codec->extradata_size) {
225
            st->codec->extradata = av_mallocz(st->codec->extradata_size);
226
            memcpy(st->codec->extradata, s[i].codec_specific, st->codec->extradata_size);
227
        }
228

  
229
        av_set_pts_info(avf->streams[i], 60, s[i].time_base.nom, s[i].time_base.den);
230
        st->start_time = 0;
231
        st->duration = s[i].max_pts;
232

  
233
        st->codec->codec_id = codec_get_id(nut_tags, st->codec->codec_tag);
234

  
235
        switch(s[i].type) {
236
        case NUT_AUDIO_CLASS:
237
            st->codec->codec_type = CODEC_TYPE_AUDIO;
238
            if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = codec_get_wav_id(st->codec->codec_tag);
239

  
240
            st->codec->channels = s[i].channel_count;
241
            st->codec->sample_rate = s[i].samplerate_nom / s[i].samplerate_denom;
242
            break;
243
        case NUT_VIDEO_CLASS:
244
            st->codec->codec_type = CODEC_TYPE_VIDEO;
245
            if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = codec_get_bmp_id(st->codec->codec_tag);
246

  
247
            st->codec->width = s[i].width;
248
            st->codec->height = s[i].height;
249
            st->codec->sample_aspect_ratio.num = s[i].sample_width;
250
            st->codec->sample_aspect_ratio.den = s[i].sample_height;
251
            break;
252
        }
253
        if (st->codec->codec_id == CODEC_ID_NONE) av_log(avf, AV_LOG_ERROR, "Unknown codec?!\n");
254
    }
255

  
256
    return 0;
257
}
258

  
259
static int nut_read_packet(AVFormatContext * avf, AVPacket * pkt) {
260
    NUTContext * priv = avf->priv_data;
261
    nut_packet_t pd;
262
    int ret;
263

  
264
    while ((ret = nut_read_next_packet(priv->nut, &pd)) < 0)
265
        av_log(avf, AV_LOG_ERROR, " NUT error: %s\n", nut_error(-ret));
266

  
267
    if (ret || av_new_packet(pkt, pd.len) < 0) return -1;
268

  
269
    if (pd.flags & NUT_FLAG_KEY) pkt->flags |= PKT_FLAG_KEY;
270
    pkt->pts = pd.pts;
271
    pkt->stream_index = pd.stream;
272
    pkt->pos = url_ftell(&avf->pb);
273

  
274
    ret = nut_read_frame(priv->nut, &pd.len, pkt->data);
275

  
276
    return ret;
277
}
278

  
279
static int nut_read_seek(AVFormatContext * avf, int stream_index, int64_t target_ts, int flags) {
280
    NUTContext * priv = avf->priv_data;
281
    int active_streams[] = { stream_index, -1 };
282
    double time_pos = target_ts * priv->s[stream_index].time_base.nom / (double)priv->s[stream_index].time_base.den;
283

  
284
    if (nut_seek(priv->nut, time_pos, 2*!(flags & AVSEEK_FLAG_BACKWARD), active_streams)) return -1;
285

  
286
    return 0;
287
}
288

  
289
static int nut_read_close(AVFormatContext *s) {
290
    NUTContext * priv = s->priv_data;
291

  
292
    nut_demuxer_uninit(priv->nut);
293
    av_free(priv->s);
294

  
295
    return 0;
296
}
297

  
298
AVInputFormat nut_demuxer = {
299
    "nut",
300
    "nut format",
301
    sizeof(NUTContext),
302
    nut_probe,
303
    nut_read_header,
304
    nut_read_packet,
305
    nut_read_close,
306
    nut_read_seek,
307
    .extensions = "nut",
308
};

Also available in: Unified diff