History

libutvideo: Add Ut Video Decoder Wrapper

Add a wrapper for libutvideo's decoder. This supports decoding the following FOURCCs: ULY0 - 4:2:0 YCbCr ULY2 - 4:2:2 YCbCr ULRG - RGB ULRA - RGBA Also, bump version.

Derek Buitenhuis committed 15 years ago

Commit 1de357d1 parent fe87b2e7 files · +244 −2Browse files

Unified · Split

7 files
  1. configure +5 −0
  2. libavcodec/Makefile +1 −0
  3. libavcodec/allcodecs.c +1 −0
  4. libavcodec/avcodec.h +1 −0
  5. libavcodec/libutvideo.cpp +230 −0
  6. libavcodec/version.h +2 −2
  7. libavformat/riff.c +4 −0
configure+5−0
@@ -185,6 +185,7 @@ External library support: · 184 unmodified lines
185185 --enable-libspeex enable Speex encoding and decoding via libspeex [no]
186186 --enable-libstagefright-h264 enable H.264 decoding via libstagefright [no]
187187 --enable-libtheora enable Theora encoding via libtheora [no]
188+ --enable-libutvideo enable Ut Video decoding via libutvideo [no]
188189 --enable-libvo-aacenc enable AAC encoding via libvo-aacenc [no]
189190 --enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no]
190191 --enable-libvorbis enable Vorbis encoding via libvorbis,
@@ -1015,6 +1016,7 @@ CONFIG_LIST=" · 824 unmodified lines
10151016 libspeex
10161017 libstagefright_h264
10171018 libtheora
1019+ libutvideo
10181020 libvo_aacenc
10191021 libvo_amrwbenc
10201022 libvorbis
@@ -1513,6 +1515,7 @@ libvpx_encoder_deps="libvpx" · 492 unmodified lines
15131515 libx264_encoder_deps="libx264"
15141516 libxavs_encoder_deps="libxavs"
15151517 libxvid_encoder_deps="libxvid"
1518+libutvideo_decoder_deps="libutvideo gpl"
15161519
15171520 # demuxers / muxers
15181521 ac3_demuxer_select="ac3_parser"
@@ -3035,6 +3038,7 @@ enabled libstagefright_h264 && require_cpp libstagefright_h264 "binder/ProcessS · 1516 unmodified lines
30353038 media/stagefright/MediaBufferGroup.h media/stagefright/MediaDebug.h media/stagefright/MediaDefs.h
30363039 media/stagefright/OMXClient.h media/stagefright/OMXCodec.h" android::OMXClient -lstagefright -lmedia -lutils -lbinder
30373040 enabled libtheora && require libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
3041+enabled libutvideo && require_cpp utvideo "stdint.h stdlib.h utvideo/utvideo.h utvideo/Codec.h" 'CCodec*' -lutvideo -lstdc++
30383042 enabled libvo_aacenc && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc
30393043 enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
30403044 enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
@@ -3361,6 +3365,7 @@ echo "libschroedinger enabled ${libschroedinger-no}" · 320 unmodified lines
33613365 echo "libspeex enabled ${libspeex-no}"
33623366 echo "libstagefright-h264 enabled ${libstagefright_h264-no}"
33633367 echo "libtheora enabled ${libtheora-no}"
3368+echo "libutvideo enabled ${libutvideo-no}"
33643369 echo "libvo-aacenc support ${libvo_aacenc-no}"
33653370 echo "libvo-amrwbenc support ${libvo_amrwbenc-no}"
33663371 echo "libvorbis enabled ${libvorbis-no}"
libavcodec/Makefile+1−0
@@ -606,6 +606,7 @@ OBJS-$(CONFIG_LIBSPEEX_DECODER) += libspeexdec.o · 605 unmodified lines
606606 OBJS-$(CONFIG_LIBSPEEX_ENCODER) += libspeexenc.o
607607 OBJS-$(CONFIG_LIBSTAGEFRIGHT_H264_DECODER)+= libstagefright.o
608608 OBJS-$(CONFIG_LIBTHEORA_ENCODER) += libtheoraenc.o
609+OBJS-$(CONFIG_LIBUTVIDEO_DECODER) += libutvideo.o
609610 OBJS-$(CONFIG_LIBVO_AACENC_ENCODER) += libvo-aacenc.o mpeg4audio.o
610611 OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o
611612 OBJS-$(CONFIG_LIBVORBIS_ENCODER) += libvorbis.o vorbis_data.o
libavcodec/allcodecs.c+1−0
@@ -389,6 +389,7 @@ void avcodec_register_all(void) · 388 unmodified lines
389389 REGISTER_ENCDEC (LIBSPEEX, libspeex);
390390 REGISTER_DECODER (LIBSTAGEFRIGHT_H264, libstagefright_h264);
391391 REGISTER_ENCODER (LIBTHEORA, libtheora);
392+ REGISTER_DECODER (LIBUTVIDEO, libutvideo);
392393 REGISTER_ENCODER (LIBVO_AACENC, libvo_aacenc);
393394 REGISTER_ENCODER (LIBVO_AMRWBENC, libvo_amrwbenc);
394395 REGISTER_ENCODER (LIBVORBIS, libvorbis);
libavcodec/avcodec.h+1−0
@@ -212,6 +212,7 @@ enum CodecID { · 211 unmodified lines
212212 CODEC_ID_VC1IMAGE,
213213 CODEC_ID_8SVX_RAW,
214214 CODEC_ID_G2M,
215+ CODEC_ID_UTVIDEO = 0x800,
215216
216217 /* various PCM "codecs" */
217218 CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
libavcodec/libutvideo.cpp+230−0
@@ -0,0 +1,230 @@
1+/*
2+ * Copyright (c) 2011 Derek Buitenhuis
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU General Public
8+ * License as published by the Free Software Foundation;
9+ * version 2 of the License.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+/**
22+ * @file
23+ * Known FOURCCs:
24+ * 'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA)
25+ */
26+
27+extern "C" {
28+#include "avcodec.h"
29+}
30+
31+#include <stdlib.h>
32+#include <utvideo/utvideo.h>
33+#include <utvideo/Codec.h>
34+
35+#include "get_bits.h"
36+
37+typedef struct {
38+ uint32_t version;
39+ uint32_t original_format;
40+ uint32_t stripes;
41+ uint32_t flags;
42+} UtVideoExtra;
43+
44+typedef struct {
45+ CCodec *codec;
46+ unsigned int buf_size;
47+ uint8_t *output;
48+} UtVideoContext;
49+
50+static av_cold int utvideo_decode_init(AVCodecContext *avctx)
51+{
52+ UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
53+ UtVideoExtra info;
54+ int defined_fourcc = 0;
55+
56+ if(avctx->extradata_size != 4*4)
57+ {
58+ av_log(avctx, AV_LOG_ERROR, "Extradata size mismatch.\n");
59+ return -1;
60+ }
61+
62+ /* Read extradata */
63+ info.version = AV_RL32(avctx->extradata);
64+ info.original_format = AV_RL32(avctx->extradata + 4);
65+ info.stripes = AV_RL32(avctx->extradata + 8);
66+ info.flags = AV_RL32(avctx->extradata + 12);
67+
68+ /* Try to output the original format */
69+ switch(UNFCC(info.original_format))
70+ {
71+ case UTVF_YV12:
72+ avctx->pix_fmt = PIX_FMT_YUV420P;
73+ break;
74+ case UTVF_YUY2:
75+ case UTVF_YUYV:
76+ case UTVF_YUNV:
77+ avctx->pix_fmt = PIX_FMT_YUYV422;
78+ break;
79+ case UTVF_UYVY:
80+ case UTVF_UYNV:
81+ avctx->pix_fmt = PIX_FMT_UYVY422;
82+ break;
83+ case UTVF_RGB24_WIN:
84+ avctx->pix_fmt = PIX_FMT_BGR24;
85+ break;
86+ case UTVF_RGB32_WIN:
87+ avctx->pix_fmt = PIX_FMT_RGB32;
88+ break;
89+ case UTVF_ARGB32_WIN:
90+ avctx->pix_fmt = PIX_FMT_ARGB;
91+ break;
92+ case 0:
93+ /* Fall back on FOURCC */
94+ switch(UNFCC(avctx->codec_tag))
95+ {
96+ case UTVF_ULY0:
97+ avctx->pix_fmt = PIX_FMT_YUV420P;
98+ defined_fourcc = UTVF_YV12;
99+ break;
100+ case UTVF_ULY2:
101+ avctx->pix_fmt = PIX_FMT_YUYV422;
102+ defined_fourcc = UTVF_YUY2;
103+ break;
104+ case UTVF_ULRG:
105+ avctx->pix_fmt = PIX_FMT_BGR24;
106+ defined_fourcc = UTVF_RGB24_WIN;
107+ break;
108+ case UTVF_ULRA:
109+ avctx->pix_fmt = PIX_FMT_RGB32;
110+ defined_fourcc = UTVF_RGB32_WIN;
111+ break;
112+ }
113+ break;
114+ default:
115+ av_log(avctx, AV_LOG_ERROR,
116+ "Codec ExtraData is Corrupt or Invalid: %X\n", info.original_format);
117+ return -1;
118+ }
119+
120+ /* Only allocate the buffer once */
121+ utv->buf_size = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
122+ utv->output = (uint8_t *)av_malloc(utv->buf_size * sizeof(uint8_t));
123+
124+ if(utv->output == NULL)
125+ {
126+ av_log(avctx, AV_LOG_ERROR, "Unable to allocate output buffer.\n");
127+ return -1;
128+ }
129+
130+ /* Allocate the output frame */
131+ avctx->coded_frame = avcodec_alloc_frame();
132+
133+ /* Ut Video only supports 8-bit */
134+ avctx->bits_per_raw_sample = 8;
135+
136+ /* Is it interlaced? */
137+ avctx->coded_frame->interlaced_frame = info.flags & 0x800 ? 1 : 0;
138+
139+ /* Apparently Ut Video doesn't store this info... */
140+ avctx->coded_frame->top_field_first = 1;
141+
142+ /*
143+ * Create a Ut Video instance. Since the function wants
144+ * an "interface name" string, pass it the name of the lib.
145+ */
146+ utv->codec = CCodec::CreateInstance(UNFCC(avctx->codec_tag), "libavcodec");
147+
148+ /* Initialize Decoding */
149+ utv->codec->DecodeBegin(defined_fourcc ? defined_fourcc : UNFCC(info.original_format),
150+ avctx->width, avctx->height, CBGROSSWIDTH_WINDOWS, &info,
151+ sizeof(UtVideoExtra));
152+
153+ return 0;
154+}
155+
156+static int utvideo_decode_frame(AVCodecContext *avctx, void *data,
157+ int *data_size, AVPacket *avpkt)
158+{
159+ UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
160+ AVFrame *pic = avctx->coded_frame;
161+ unsigned int w = avctx->width, h = avctx->height;
162+
163+ /* Set flags */
164+ pic->reference = 0;
165+ pic->pict_type = AV_PICTURE_TYPE_I;
166+ pic->key_frame = 1;
167+
168+ /* Decode the frame */
169+ utv->codec->DecodeFrame(utv->output, avpkt->data, true);
170+
171+ /* Set the output data depending on the colorspace */
172+ switch(avctx->pix_fmt)
173+ {
174+ case PIX_FMT_YUV420P:
175+ pic->linesize[0] = w;
176+ pic->linesize[1] = pic->linesize[2] = w / 2;
177+ pic->data[0] = utv->output;
178+ pic->data[2] = utv->output + (w * h);
179+ pic->data[1] = pic->data[2] + (w * h / 4);
180+ break;
181+ case PIX_FMT_YUYV422:
182+ case PIX_FMT_UYVY422:
183+ pic->linesize[0] = w * 2;
184+ pic->data[0] = utv->output;
185+ break;
186+ case PIX_FMT_BGR24:
187+ case PIX_FMT_RGB32:
188+ /* Make the linesize negative, since Ut Video uses bottom-up BGR */
189+ pic->linesize[0] = -1 * w * (avctx->pix_fmt == PIX_FMT_BGR24 ? 3 : 4);
190+ pic->data[0] = utv->output + utv->buf_size + pic->linesize[0];
191+ break;
192+ }
193+
194+ *data_size = sizeof(AVFrame);
195+ *(AVFrame *)data = *pic;
196+
197+ return avpkt->size;
198+}
199+
200+static av_cold int utvideo_decode_close(AVCodecContext *avctx)
201+{
202+ UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
203+
204+ /* Free output */
205+ av_freep(&avctx->coded_frame);
206+ av_freep(&utv->output);
207+
208+ /* Finish decoding and clean up the instance */
209+ utv->codec->DecodeEnd();
210+ CCodec::DeleteInstance(utv->codec);
211+
212+ return 0;
213+}
214+
215+AVCodec ff_libutvideo_decoder = {
216+ "utvideo",
217+ AVMEDIA_TYPE_VIDEO,
218+ CODEC_ID_UTVIDEO,
219+ sizeof(UtVideoContext),
220+ utvideo_decode_init,
221+ NULL,
222+ utvideo_decode_close,
223+ utvideo_decode_frame,
224+ CODEC_CAP_LOSSLESS,
225+ NULL,
226+ NULL,
227+ NULL,
228+ NULL,
229+ NULL_IF_CONFIG_SMALL("Ut Video"),
230+};
libavcodec/version.h+2−2
@@ -21,8 +21,8 @@ · 20 unmodified lines
2121 #define AVCODEC_VERSION_H
2222
2323 #define LIBAVCODEC_VERSION_MAJOR 53
24−#define LIBAVCODEC_VERSION_MINOR 20
25−#define LIBAVCODEC_VERSION_MICRO 1
24+#define LIBAVCODEC_VERSION_MINOR 21
25+#define LIBAVCODEC_VERSION_MICRO 0
2626
2727 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
2828 LIBAVCODEC_VERSION_MINOR, \
libavformat/riff.c+4−0
@@ -281,6 +281,10 @@ const AVCodecTag ff_codec_bmp_tags[] = { · 280 unmodified lines
281281 { CODEC_ID_G2M, MKTAG('G', '2', 'M', '3') },
282282 { CODEC_ID_G2M, MKTAG('G', '2', 'M', '4') },
283283 { CODEC_ID_AMV, MKTAG('A', 'M', 'V', 'F') },
284+ { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'Y', '0') },
285+ { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'Y', '2') },
286+ { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'R', 'G') },
287+ { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'R', 'A') },
284288 { CODEC_ID_NONE, 0 }
285289 };
286290

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t