]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/asf-enc.c
move framecrc muxer in its own file
[ffmpeg] / libavformat / asf-enc.c
index 2a87591e936fd6156a8648f8ed0bac04f0c802c4..736c1365af02e30d19e61c112f7a096eba7f6f52 100644 (file)
@@ -194,7 +194,7 @@ static const AVCodecTag codec_asf_bmp_tags[] = {
     { CODEC_ID_NONE, 0 },
 };
 
-static int preroll_time = 3100;
+#define PREROLL_TIME 3100
 
 static void put_guid(ByteIOContext *s, const GUID *g)
 {
@@ -278,7 +278,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
     int bit_rate;
     int64_t duration;
 
-    duration = asf->duration + preroll_time * 10000;
+    duration = asf->duration + PREROLL_TIME * 10000;
     has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);
 
     bit_rate = 0;
@@ -309,10 +309,9 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
     put_le64(pb, unix_to_file_time(file_time));
     put_le64(pb, asf->nb_packets); /* number of packets */
     put_le64(pb, duration); /* end time stamp (in 100ns units) */
-    put_le64(pb, duration); /* duration (in 100ns units) */
-    put_le32(pb, preroll_time); /* start time stamp */
-    put_le32(pb, 0); /* ??? */
-    put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */
+    put_le64(pb, asf->duration); /* duration (in 100ns units) */
+    put_le64(pb, PREROLL_TIME); /* start time stamp */
+    put_le32(pb, (asf->is_streamed || url_is_streamed(pb)) ? 3 : 2); /* ??? */
     put_le32(pb, asf->packet_size); /* packet size */
     put_le32(pb, asf->packet_size); /* packet size */
     put_le32(pb, bit_rate); /* Nominal data rate in bps */
@@ -429,8 +428,17 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
         enc = s->streams[n]->codec;
         p = avcodec_find_encoder(enc->codec_id);
 
-        put_le16(pb, asf->streams[n].num);
-        put_str16(pb, p ? p->name : enc->codec_name);
+        if(enc->codec_type == CODEC_TYPE_AUDIO)
+            put_le16(pb, 2);
+        else if(enc->codec_type == CODEC_TYPE_VIDEO)
+            put_le16(pb, 1);
+        else
+            put_le16(pb, -1);
+
+        if(enc->codec_id == CODEC_ID_WMAV2)
+            put_str16(pb, "Windows Media Audio V8");
+        else
+            put_str16(pb, p ? p->name : enc->codec_name);
         put_le16(pb, 0); /* no parameters */
 
 
@@ -490,6 +498,9 @@ static int asf_write_header(AVFormatContext *s)
     asf->nb_index_count = 0;
     asf->maximum_packet = 0;
 
+    /* the data-chunk-size has to be 50, which is data_size - asf->data_offset
+     *  at the moment this function is done. It is needed to use asf as
+     *  streamable format. */
     if (asf_write_header1(s, 0, 50) < 0) {
         //av_free(asf);
         return -1;
@@ -640,6 +651,7 @@ static void put_payload_header(
 static void put_frame(
                     AVFormatContext *s,
                     ASFStream       *stream,
+                    AVStream        *avst,
                     int             timestamp,
                     const uint8_t   *buf,
                     int             m_obj_size,
@@ -669,6 +681,11 @@ static void put_frame(
             frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS - PACKET_HEADER_MIN_SIZE - 1;
 
             asf->packet_timestamp_start = timestamp;
+
+            if(frag_len1 < payload_len && avst->codec->codec_type == CODEC_TYPE_AUDIO){
+                flush_packet(s);
+                continue;
+            }
         }
         if (frag_len1 > 0) {
             if (payload_len > frag_len1)
@@ -676,7 +693,7 @@ static void put_frame(
             else if (payload_len == (frag_len1 - 1))
                 payload_len = frag_len1 - 2;  //additional byte need to put padding length
 
-            put_payload_header(s, stream, timestamp+preroll_time, m_obj_size, m_obj_offset, payload_len, flags);
+            put_payload_header(s, stream, timestamp+PREROLL_TIME, m_obj_size, m_obj_offset, payload_len, flags);
             put_buffer(&asf->pb, buf, payload_len);
 
             if (asf->multi_payloads_present)
@@ -723,7 +740,7 @@ static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
     asf->duration= FFMAX(asf->duration, duration);
 
     packet_st = asf->nb_packets;
-    put_frame(s, stream, pkt->dts, pkt->data, pkt->size, flags);
+    put_frame(s, stream, s->streams[pkt->stream_index], pkt->dts, pkt->data, pkt->size, flags);
 
     /* check index */
     if ((!asf->is_streamed) && (flags & PKT_FLAG_KEY)) {
@@ -782,7 +799,7 @@ static int asf_write_trailer(AVFormatContext *s)
     }
     put_flush_packet(&s->pb);
 
-    if (asf->is_streamed) {
+    if (asf->is_streamed || url_is_streamed(&s->pb)) {
         put_chunk(s, 0x4524, 0, 0); /* end of stream */
     } else {
         /* rewrite an updated header */