[libav-devel] [PATCH 1/2] nut: prioritize native tags

2012-10-12 Thread Luca Barbato
Use native tags instead of avi ones, simplifies a lot raw video codecs
handling.
---
 libavformat/nut.c|   6 +++
 libavformat/nut.h|   2 +
 libavformat/nutdec.c |   7 +--
 libavformat/nutenc.c |  15 +++---
 tests/ref/lavfi/crop |   2 +-
 tests/ref/lavfi/crop_scale   |   2 +-
 tests/ref/lavfi/crop_scale_vflip |   2 +-
 tests/ref/lavfi/crop_vflip   |   2 +-
 tests/ref/lavfi/null |   2 +-
 tests/ref/lavfi/pixdesc  | 114 +++
 tests/ref/lavfi/pixfmts_copy | 114 +++
 tests/ref/lavfi/pixfmts_crop |  82 ++--
 tests/ref/lavfi/pixfmts_hflip|  82 ++--
 tests/ref/lavfi/pixfmts_null | 114 +++
 tests/ref/lavfi/pixfmts_pad  |  34 ++--
 tests/ref/lavfi/pixfmts_scale| 114 +++
 tests/ref/lavfi/pixfmts_vflip| 114 +++
 tests/ref/lavfi/scale200 |   2 +-
 tests/ref/lavfi/scale500 |   2 +-
 tests/ref/lavfi/vflip|   2 +-
 tests/ref/lavfi/vflip_crop   |   2 +-
 tests/ref/lavfi/vflip_vflip  |   2 +-
 22 files changed, 413 insertions(+), 405 deletions(-)

diff --git a/libavformat/nut.c b/libavformat/nut.c
index 6a68e28..b666bff 100644
--- a/libavformat/nut.c
+++ b/libavformat/nut.c
@@ -22,6 +22,7 @@
 #include libavutil/mathematics.h
 #include libavutil/tree.h
 #include nut.h
+#include riff.h
 #include internal.h
 
 const AVCodecTag ff_nut_subtitle_tags[] = {
@@ -89,6 +90,11 @@ const AVCodecTag ff_nut_video_tags[] = {
 { AV_CODEC_ID_NONE, 0 }
 };
 
+const AVCodecTag * const ff_nut_codec_tags[] = {
+ff_nut_video_tags, ff_nut_subtitle_tags,
+ff_codec_bmp_tags, ff_codec_wav_tags, 0
+};
+
 void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val){
 int i;
 for(i=0; inut-avf-nb_streams; i++){
diff --git a/libavformat/nut.h b/libavformat/nut.h
index 3f09689..335eceb 100644
--- a/libavformat/nut.h
+++ b/libavformat/nut.h
@@ -106,6 +106,8 @@ typedef struct NUTContext {
 extern const AVCodecTag ff_nut_subtitle_tags[];
 extern const AVCodecTag ff_nut_video_tags[];
 
+extern const AVCodecTag * const ff_nut_codec_tags[];
+
 typedef struct Dispositions {
 char str[9];
 int flag;
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index dd02aad..8448e13 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -350,8 +350,8 @@ static int decode_stream_header(NUTContext *nut)
 case 0:
 st-codec-codec_type = AVMEDIA_TYPE_VIDEO;
 st-codec-codec_id   = av_codec_get_id((const AVCodecTag * const []) {
-ff_codec_bmp_tags,
 ff_nut_video_tags,
+ff_codec_bmp_tags,
 0
 },
 tmp);
@@ -991,8 +991,5 @@ AVInputFormat ff_nut_demuxer = {
 .read_close = nut_read_close,
 .read_seek  = read_seek,
 .extensions = nut,
-.codec_tag  = (const AVCodecTag * const []) {
-ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags,
-ff_nut_subtitle_tags, 0
-},
+.codec_tag  = ff_nut_codec_tags,
 };
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 4b1e663..6338924 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -374,6 +374,8 @@ static void write_mainheader(NUTContext *nut, AVIOContext 
*bc){
 static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, 
AVStream *st, int i){
 NUTContext *nut = avctx-priv_data;
 AVCodecContext *codec = st-codec;
+unsigned codec_tag = av_codec_get_tag(ff_nut_codec_tags, codec-codec_id);
+
 ff_put_v(bc, i);
 switch(codec-codec_type){
 case AVMEDIA_TYPE_VIDEO: ff_put_v(bc, 0); break;
@@ -382,8 +384,12 @@ static int write_streamheader(AVFormatContext *avctx, 
AVIOContext *bc, AVStream
 default  : ff_put_v(bc, 3); break;
 }
 ff_put_v(bc, 4);
-if (codec-codec_tag){
-avio_wl32(bc, codec-codec_tag);
+
+if (!codec_tag)
+codec_tag = codec-codec_tag;
+
+if (codec_tag) {
+avio_wl32(bc, codec_tag);
 } else {
 av_log(avctx, AV_LOG_ERROR, No codec tag defined for stream %d\n, i);
 return AVERROR(EINVAL);
@@ -873,8 +879,5 @@ AVOutputFormat ff_nut_muxer = {
 .write_packet   = nut_write_packet,
 .write_trailer  = nut_write_trailer,
 .flags  = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
-.codec_tag  = (const AVCodecTag * const []){
-ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags,
-ff_nut_subtitle_tags, 0
-},
+.codec_tag  

[libav-devel] [PATCH 1/2] nut: prioritize native tags

2012-10-12 Thread Luca Barbato
Use native tags instead of avi ones, simplifies a lot raw video codecs
handling.
---
 libavformat/nut.c|   6 +++
 libavformat/nut.h|   2 +
 libavformat/nutdec.c |   7 +--
 libavformat/nutenc.c |  15 +++---
 tests/ref/lavfi/crop |   2 +-
 tests/ref/lavfi/crop_scale   |   2 +-
 tests/ref/lavfi/crop_scale_vflip |   2 +-
 tests/ref/lavfi/crop_vflip   |   2 +-
 tests/ref/lavfi/null |   2 +-
 tests/ref/lavfi/pixdesc  | 114 +++
 tests/ref/lavfi/pixfmts_copy | 114 +++
 tests/ref/lavfi/pixfmts_crop |  82 ++--
 tests/ref/lavfi/pixfmts_hflip|  82 ++--
 tests/ref/lavfi/pixfmts_null | 114 +++
 tests/ref/lavfi/pixfmts_pad  |  34 ++--
 tests/ref/lavfi/pixfmts_scale| 114 +++
 tests/ref/lavfi/pixfmts_vflip| 114 +++
 tests/ref/lavfi/scale200 |   2 +-
 tests/ref/lavfi/scale500 |   2 +-
 tests/ref/lavfi/vflip|   2 +-
 tests/ref/lavfi/vflip_crop   |   2 +-
 tests/ref/lavfi/vflip_vflip  |   2 +-
 22 files changed, 413 insertions(+), 405 deletions(-)

diff --git a/libavformat/nut.c b/libavformat/nut.c
index 6a68e28..b666bff 100644
--- a/libavformat/nut.c
+++ b/libavformat/nut.c
@@ -22,6 +22,7 @@
 #include libavutil/mathematics.h
 #include libavutil/tree.h
 #include nut.h
+#include riff.h
 #include internal.h
 
 const AVCodecTag ff_nut_subtitle_tags[] = {
@@ -89,6 +90,11 @@ const AVCodecTag ff_nut_video_tags[] = {
 { AV_CODEC_ID_NONE, 0 }
 };
 
+const AVCodecTag * const ff_nut_codec_tags[] = {
+ff_nut_video_tags, ff_nut_subtitle_tags,
+ff_codec_bmp_tags, ff_codec_wav_tags, 0
+};
+
 void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val){
 int i;
 for(i=0; inut-avf-nb_streams; i++){
diff --git a/libavformat/nut.h b/libavformat/nut.h
index 3f09689..335eceb 100644
--- a/libavformat/nut.h
+++ b/libavformat/nut.h
@@ -106,6 +106,8 @@ typedef struct NUTContext {
 extern const AVCodecTag ff_nut_subtitle_tags[];
 extern const AVCodecTag ff_nut_video_tags[];
 
+extern const AVCodecTag * const ff_nut_codec_tags[];
+
 typedef struct Dispositions {
 char str[9];
 int flag;
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index dd02aad..8448e13 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -350,8 +350,8 @@ static int decode_stream_header(NUTContext *nut)
 case 0:
 st-codec-codec_type = AVMEDIA_TYPE_VIDEO;
 st-codec-codec_id   = av_codec_get_id((const AVCodecTag * const []) {
-ff_codec_bmp_tags,
 ff_nut_video_tags,
+ff_codec_bmp_tags,
 0
 },
 tmp);
@@ -991,8 +991,5 @@ AVInputFormat ff_nut_demuxer = {
 .read_close = nut_read_close,
 .read_seek  = read_seek,
 .extensions = nut,
-.codec_tag  = (const AVCodecTag * const []) {
-ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags,
-ff_nut_subtitle_tags, 0
-},
+.codec_tag  = ff_nut_codec_tags,
 };
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 4b1e663..6338924 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -374,6 +374,8 @@ static void write_mainheader(NUTContext *nut, AVIOContext 
*bc){
 static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, 
AVStream *st, int i){
 NUTContext *nut = avctx-priv_data;
 AVCodecContext *codec = st-codec;
+unsigned codec_tag = av_codec_get_tag(ff_nut_codec_tags, codec-codec_id);
+
 ff_put_v(bc, i);
 switch(codec-codec_type){
 case AVMEDIA_TYPE_VIDEO: ff_put_v(bc, 0); break;
@@ -382,8 +384,12 @@ static int write_streamheader(AVFormatContext *avctx, 
AVIOContext *bc, AVStream
 default  : ff_put_v(bc, 3); break;
 }
 ff_put_v(bc, 4);
-if (codec-codec_tag){
-avio_wl32(bc, codec-codec_tag);
+
+if (!codec_tag)
+codec_tag = codec-codec_tag;
+
+if (codec_tag) {
+avio_wl32(bc, codec_tag);
 } else {
 av_log(avctx, AV_LOG_ERROR, No codec tag defined for stream %d\n, i);
 return AVERROR(EINVAL);
@@ -873,8 +879,5 @@ AVOutputFormat ff_nut_muxer = {
 .write_packet   = nut_write_packet,
 .write_trailer  = nut_write_trailer,
 .flags  = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
-.codec_tag  = (const AVCodecTag * const []){
-ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags,
-ff_nut_subtitle_tags, 0
-},
+.codec_tag