changeset 5719:65b13165daaf libavformat

asfenc: simplify writing of comment header. Patch by Anton Khirnov wyskas gmail com
author benoit
date Thu, 25 Feb 2010 16:50:26 +0000
parents db8bae128461
children d833557e7287
files asfenc.c
diffstat 1 files changed, 12 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/asfenc.c	Thu Feb 25 16:38:23 2010 +0000
+++ b/asfenc.c	Thu Feb 25 16:50:26 2010 +0000
@@ -265,7 +265,7 @@
 {
     ASFContext *asf = s->priv_data;
     ByteIOContext *pb = s->pb;
-    AVMetadataTag *title, *author, *copyright, *comment;
+    AVMetadataTag *tags[5];
     int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
     int has_title;
     int metadata_count;
@@ -274,13 +274,14 @@
     int bit_rate;
     int64_t duration;
 
-    title     = av_metadata_get(s->metadata, "title"    , NULL, 0);
-    author    = av_metadata_get(s->metadata, "author"   , NULL, 0);
-    copyright = av_metadata_get(s->metadata, "copyright", NULL, 0);
-    comment   = av_metadata_get(s->metadata, "comment"  , NULL, 0);
+    tags[0] = av_metadata_get(s->metadata, "title"    , NULL, 0);
+    tags[1] = av_metadata_get(s->metadata, "author"   , NULL, 0);
+    tags[2] = av_metadata_get(s->metadata, "copyright", NULL, 0);
+    tags[3] = av_metadata_get(s->metadata, "comment"  , NULL, 0);
+    tags[4] = av_metadata_get(s->metadata, "rating"   , NULL, 0);
 
     duration = asf->duration + PREROLL_TIME * 10000;
-    has_title = title || author || copyright || comment;
+    has_title = tags[0] || tags[1] || tags[2] || tags[3] || tags[4];
     metadata_count = s->metadata ? s->metadata->count : 0;
 
     bit_rate = 0;
@@ -329,15 +330,11 @@
     /* title and other infos */
     if (has_title) {
         hpos = put_header(pb, &ff_asf_comment_header);
-        put_le16(pb, title     ? 2 * (strlen(title->value    ) + 1) : 0);
-        put_le16(pb, author    ? 2 * (strlen(author->value   ) + 1) : 0);
-        put_le16(pb, copyright ? 2 * (strlen(copyright->value) + 1) : 0);
-        put_le16(pb, comment   ? 2 * (strlen(comment->value  ) + 1) : 0);
-        put_le16(pb, 0);
-        if (title    ) put_str16_nolen(pb, title->value    );
-        if (author   ) put_str16_nolen(pb, author->value   );
-        if (copyright) put_str16_nolen(pb, copyright->value);
-        if (comment  ) put_str16_nolen(pb, comment->value  );
+        for (n = 0; n < FF_ARRAY_ELEMS(tags); n++)
+            put_le16(pb, tags[n] ? 2*(strlen(tags[n]->value) + 1) : 0);
+        for (n = 0; n < FF_ARRAY_ELEMS(tags); n++)
+            if (tags[n])
+                put_str16_nolen(pb, tags[n]->value);
         end_header(pb, hpos);
     }
     if (metadata_count) {