[PATCH 4/5] Define the ff_nut_raw_video_pixel_format_tags table and make the muxer and demuxer use it.
Stefano Sabatini
stefano.sabatini-lala
Sun Mar 28 11:39:52 CEST 2010
Nut pixel-format <-> codec-tag mapping is specific to nut, that's why
we need to use the ff_nut_raw_video_pixel_format_tags table, because
adding these entries in other shared tables (e.g. in
libavcodec/raw.c:ff_raw_pixelFormatTags) may conflict with the tags
used by other container formats.
---
libavformat/nut.c | 21 +++++++++++++++++++++
libavformat/nut.h | 3 +++
libavformat/nutdec.c | 8 +++++++-
libavformat/nutenc.c | 11 ++++++++---
4 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/libavformat/nut.c b/libavformat/nut.c
index 9a6a41b..f279928 100644
--- a/libavformat/nut.c
+++ b/libavformat/nut.c
@@ -22,6 +22,27 @@
#include "libavutil/tree.h"
#include "nut.h"
+const PixelFormatTag ff_nut_raw_video_pixel_format_tags[] = {
+ { PIX_FMT_RGB555LE, MKTAG('R', 'G', 'B', 15) },
+ { PIX_FMT_BGR555LE, MKTAG('B', 'G', 'R', 15) },
+ { PIX_FMT_RGB565LE, MKTAG('R', 'G', 'B', 16) },
+ { PIX_FMT_BGR565LE, MKTAG('B', 'G', 'R', 16) },
+
+ { PIX_FMT_RGB555BE, MKTAG( 15, 'B', 'G', 'R') },
+ { PIX_FMT_BGR555BE, MKTAG( 15, 'R', 'G', 'B') },
+ { PIX_FMT_RGB565BE, MKTAG( 16, 'B', 'G', 'R') },
+ { PIX_FMT_BGR565BE, MKTAG( 16, 'R', 'G', 'B') },
+
+ { PIX_FMT_RGBA, MKTAG('R', 'G', 'B', 'A') },
+ { PIX_FMT_BGRA, MKTAG('B', 'G', 'R', 'A') },
+ { PIX_FMT_ABGR, MKTAG('A', 'B', 'G', 'R') },
+ { PIX_FMT_ARGB, MKTAG('A', 'R', 'G', 'B') },
+ { PIX_FMT_RGB24, MKTAG('R', 'G', 'B', 24) },
+ { PIX_FMT_BGR24, MKTAG('B', 'G', 'R', 24) },
+
+ { PIX_FMT_NONE, 0 },
+};
+
const AVCodecTag ff_nut_subtitle_tags[] = {
{ CODEC_ID_TEXT , MKTAG('U', 'T', 'F', '8') },
{ CODEC_ID_SSA , MKTAG('S', 'S', 'A', 0 ) },
diff --git a/libavformat/nut.h b/libavformat/nut.h
index ce052df..1c0da25 100644
--- a/libavformat/nut.h
+++ b/libavformat/nut.h
@@ -25,6 +25,7 @@
//#include <limits.h>
//#include "libavutil/adler32.h"
//#include "libavcodec/mpegaudio.h"
+#include "libavcodec/raw.h"
#include "avformat.h"
#include "riff.h"
#include "metadata.h"
@@ -98,6 +99,8 @@ typedef struct {
struct AVTreeNode *syncpoints;
} NUTContext;
+extern const PixelFormatTag ff_nut_raw_video_pixel_format_tags[];
+
extern const AVCodecTag ff_nut_subtitle_tags[];
typedef struct {
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index d08683f..a70cf63 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -24,6 +24,7 @@
#include "libavutil/avstring.h"
#include "libavutil/bswap.h"
#include "libavutil/tree.h"
+#include "libavcodec/internal.h"
#include "nut.h"
#undef NDEBUG
@@ -316,7 +317,12 @@ static int decode_stream_header(NUTContext *nut){
{
case 0:
st->codec->codec_type = CODEC_TYPE_VIDEO;
- st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tmp);
+ if (!(st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tmp))) {
+ st->codec->pix_fmt =
+ ff_get_pix_fmt_from_codec_tag(ff_nut_raw_video_pixel_format_tags, tmp);
+ if (st->codec->pix_fmt != PIX_FMT_NONE)
+ st->codec->codec_id = CODEC_ID_RAWVIDEO;
+ }
break;
case 1:
st->codec->codec_type = CODEC_TYPE_AUDIO;
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 84ea290..ef18f50 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -22,6 +22,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/tree.h"
#include "libavcodec/mpegaudiodata.h"
+#include "libavcodec/internal.h"
#include "nut.h"
static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint8_t out[64]){
@@ -392,6 +393,8 @@ static void write_mainheader(NUTContext *nut, ByteIOContext *bc){
static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVStream *st, int i){
AVCodecContext *codec = st->codec;
+ int codec_tag;
+
put_v(bc, i);
switch(codec->codec_type){
case CODEC_TYPE_VIDEO: put_v(bc, 0); break;
@@ -400,9 +403,11 @@ static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVStream *st,
default : put_v(bc, 3); break;
}
put_v(bc, 4);
- if (codec->codec_tag){
- put_le32(bc, codec->codec_tag);
- }else
+ if (codec->codec_type == CODEC_TYPE_VIDEO && !(codec_tag = codec->codec_tag))
+ codec_tag = ff_get_codec_tag_from_pix_fmt(ff_nut_raw_video_pixel_format_tags, codec->pix_fmt);
+ if (codec_tag)
+ put_le32(bc, codec_tag);
+ else
return -1;
put_v(bc, nut->stream[i].time_base - nut->time_base);
--
1.7.0
--6c2NcOVqGQ03X4Wi--
More information about the ffmpeg-devel
mailing list