]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/nutenc.c
Move doxygen documentation from lzo.c to lzo.h
[ffmpeg] / libavformat / nutenc.c
index de5ae6b2c3a85adab9204f94c29ea6dd5c33f4fe..1e5f733194d3b0e0ee97bcb91ab95d56dd7fea51 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
+#include "libavutil/tree.h"
+#include "libavcodec/mpegaudiodata.h"
 #include "nut.h"
-#include "tree.h"
-#include "mpegaudiodata.h"
 
 static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint8_t out[64]){
     int sample_rate= c->sample_rate;
@@ -69,7 +70,7 @@ static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint
         header |= 1<<16; //no crc
         AV_WB32(out, header);
         if(size <= 0)
-            return 2; //we guess theres no crc, if there is one the user clearly doesnt care about overhead
+            return 2; //we guess there is no crc, if there is one the user clearly does not care about overhead
         if(bitrate_index == 30)
             return -1; //something is wrong ...
 
@@ -78,8 +79,8 @@ static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint
         header |= (bitrate_index&1)<<9;
 
         return 2; //FIXME actually put the needed ones in build_elision_headers()
-        return 3; //we guess that the private bit isnt set
-//FIXME the above asumtations should be checked, if these turn out false too often something should be done
+        return 3; //we guess that the private bit is not set
+//FIXME the above assumptions should be checked, if these turn out false too often something should be done
     }
     return 0;
 }
@@ -260,7 +261,7 @@ static void put_v(ByteIOContext *bc, uint64_t val){
     put_byte(bc, val&127);
 }
 
-static void put_t(NUTContext *nut, StreamContext *nus, ByteIOContext *bc, uint64_t val){
+static void put_tt(NUTContext *nut, StreamContext *nus, ByteIOContext *bc, uint64_t val){
     val *= nut->time_base_count;
     val += nus->time_base - nut->time_base;
     put_v(bc, val);
@@ -389,7 +390,8 @@ static void write_mainheader(NUTContext *nut, ByteIOContext *bc){
     }
 }
 
-static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVCodecContext *codec, int i){
+static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVStream *st, int i){
+    AVCodecContext *codec = st->codec;
     put_v(bc, i);
     switch(codec->codec_type){
     case CODEC_TYPE_VIDEO: put_v(bc, 0); break;
@@ -422,12 +424,12 @@ static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVCodecContext
         put_v(bc, codec->width);
         put_v(bc, codec->height);
 
-        if(codec->sample_aspect_ratio.num<=0 || codec->sample_aspect_ratio.den<=0){
+        if(st->sample_aspect_ratio.num<=0 || st->sample_aspect_ratio.den<=0){
             put_v(bc, 0);
             put_v(bc, 0);
         }else{
-            put_v(bc, codec->sample_aspect_ratio.num);
-            put_v(bc, codec->sample_aspect_ratio.den);
+            put_v(bc, st->sample_aspect_ratio.num);
+            put_v(bc, st->sample_aspect_ratio.den);
         }
         put_v(bc, 0); /* csp type -- unknown */
         break;
@@ -472,6 +474,37 @@ static int write_globalinfo(NUTContext *nut, ByteIOContext *bc){
     return 0;
 }
 
+static int write_streaminfo(NUTContext *nut, ByteIOContext *bc, int stream_id){
+    AVFormatContext *s= nut->avf;
+    AVStream* st = s->streams[stream_id];
+    ByteIOContext *dyn_bc;
+    uint8_t *dyn_buf=NULL;
+    int count=0, dyn_size, i;
+    int ret = url_open_dyn_buf(&dyn_bc);
+    if(ret < 0)
+        return ret;
+
+    for (i=0; ff_nut_dispositions[i].flag; ++i) {
+        if (st->disposition & ff_nut_dispositions[i].flag)
+            count += add_info(dyn_bc, "Disposition", ff_nut_dispositions[i].str);
+    }
+    dyn_size = url_close_dyn_buf(dyn_bc, &dyn_buf);
+
+    if (count) {
+        put_v(bc, stream_id + 1); //stream_id_plus1
+        put_v(bc, 0); //chapter_id
+        put_v(bc, 0); //timestamp_start
+        put_v(bc, 0); //length
+
+        put_v(bc, count);
+
+        put_buffer(bc, dyn_buf, dyn_size);
+    }
+
+    av_free(dyn_buf);
+    return count;
+}
+
 static int write_headers(NUTContext *nut, ByteIOContext *bc){
     ByteIOContext *dyn_bc;
     int i, ret;
@@ -483,12 +516,10 @@ static int write_headers(NUTContext *nut, ByteIOContext *bc){
     put_packet(nut, bc, dyn_bc, 1, MAIN_STARTCODE);
 
     for (i=0; i < nut->avf->nb_streams; i++){
-        AVCodecContext *codec = nut->avf->streams[i]->codec;
-
         ret = url_open_dyn_buf(&dyn_bc);
         if(ret < 0)
             return ret;
-        write_streamheader(nut, dyn_bc, codec, i);
+        write_streamheader(nut, dyn_bc, nut->avf->streams[i], i);
         put_packet(nut, bc, dyn_bc, 1, STREAM_STARTCODE);
     }
 
@@ -498,6 +529,22 @@ static int write_headers(NUTContext *nut, ByteIOContext *bc){
     write_globalinfo(nut, dyn_bc);
     put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE);
 
+    for (i = 0; i < nut->avf->nb_streams; i++) {
+        ret = url_open_dyn_buf(&dyn_bc);
+        if(ret < 0)
+            return ret;
+        ret = write_streaminfo(nut, dyn_bc, i);
+        if (ret < 0)
+            return ret;
+        if (ret > 0)
+            put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE);
+        else {
+            uint8_t* buf;
+            url_close_dyn_buf(dyn_bc, &buf);
+            av_free(buf);
+        }
+    }
+
     nut->last_syncpoint_pos= INT_MIN;
     nut->header_count++;
     return 0;
@@ -603,6 +650,9 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt){
     int store_sp=0;
     int ret;
 
+    if(pkt->pts < 0)
+        return -1;
+
     if(1LL<<(20+3*nut->header_count) <= url_ftell(bc))
         write_headers(nut, bc);
 
@@ -615,7 +665,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt){
 //FIXME: Ensure store_sp is 1 in the first place.
 
     if(store_sp){
-        syncpoint_t *sp, dummy= {.pos= INT64_MAX};
+        Syncpoint *sp, dummy= {.pos= INT64_MAX};
 
         ff_nut_reset_ts(nut, *nus->time_base, pkt->dts);
         for(i=0; i<s->nb_streams; i++){
@@ -635,7 +685,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt){
         ret = url_open_dyn_buf(&dyn_bc);
         if(ret < 0)
             return ret;
-        put_t(nut, nus, dyn_bc, pkt->dts);
+        put_tt(nut, nus, dyn_bc, pkt->dts);
         put_v(dyn_bc, sp ? (nut->last_syncpoint_pos - sp->pos)>>4 : 0);
         put_packet(nut, bc, dyn_bc, 1, SYNCPOINT_STARTCODE);
 
@@ -755,21 +805,21 @@ static int write_trailer(AVFormatContext *s){
 
 AVOutputFormat nut_muxer = {
     "nut",
-    "nut format",
+    NULL_IF_CONFIG_SMALL("NUT format"),
     "video/x-nut",
     "nut",
     sizeof(NUTContext),
-#ifdef CONFIG_LIBVORBIS
+#if   CONFIG_LIBVORBIS
     CODEC_ID_VORBIS,
-#elif defined(CONFIG_LIBMP3LAME)
+#elif CONFIG_LIBMP3LAME
     CODEC_ID_MP3,
 #else
-    CODEC_ID_MP2, /* AC3 needs liba52 decoder */
+    CODEC_ID_MP2,
 #endif
     CODEC_ID_MPEG4,
     write_header,
     write_packet,
     write_trailer,
     .flags = AVFMT_GLOBALHEADER,
-    .codec_tag= (const AVCodecTag*[]){codec_bmp_tags, codec_wav_tags, ff_nut_subtitle_tags, 0},
+    .codec_tag= (const AVCodecTag* const []){codec_bmp_tags, codec_wav_tags, ff_nut_subtitle_tags, 0},
 };