brillcodec: enable some x264 encode options.
authorSooyoung Ha <yoosah.ha@samsung.com>
Tue, 26 May 2015 05:48:58 +0000 (14:48 +0900)
committerSooyoung Ha <yoosah.ha@samsung.com>
Wed, 27 May 2015 08:21:42 +0000 (17:21 +0900)
This configure options are set on init time. And I change the
if-else style legacy code to switch-case style for maintain.

Change-Id: I7fdafa2fd3f02b0abb209a60be0d9cbffc40867d
Signed-off-by: Sooyoung Ha <yoosah.ha@samsung.com>
tizen/src/hw/pci/maru_brillcodec.c

index 6a513ed..f5fbdaf 100644 (file)
@@ -896,7 +896,13 @@ static void copy_video_encode_data(void *dst, void *opaque, size_t dummy)
         if (dc->avctx->coded_frame) {
             encode_output->coded_frame = 1;
             // if key_frame is 0, this frame cannot be decoded independently.
-            encode_output->key_frame = dc->avctx->coded_frame->key_frame;
+            // TODO: check whether this has dependency to dc->avctx->coded_frame
+            if (dc->avctx->codec_id == AV_CODEC_ID_H264) {
+                 encode_output->key_frame = dc->avpkt->flags;
+             } else {
+                 encode_output->key_frame = dc->avctx->coded_frame->key_frame;
+             }
+
         }
 
         memcpy(&encode_output->data, dc->avpkt->data, dc->avpkt->size);
@@ -1875,21 +1881,43 @@ static bool init(MaruBrillCodecState *s, int ctx_id, void *data_buf)
             size = sizeof(int32_t) + 32; // buffer size of codec_name
             read_codec_init_data(avctx, elem->opaque + size);
 
-            // in case of aac encoder, sample format is float
-            if (!strcmp(codec->name, "aac") && codec->encode2) {
-                LOG_TRACE("convert sample format into SAMPLE_FMT_FLTP\n");
-                avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
-
-                avctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
-
-                LOG_INFO("aac encoder!! channels %d channel_layout %lld\n", avctx->channels, avctx->channel_layout);
-                avctx->channel_layout = av_get_default_channel_layout(avctx->channels);
+            AVDictionary *opts = NULL;
+
+            if (codec->encode2) {
+                avctx->gop_size = DEFAULT_VIDEO_GOP_SIZE;
+
+                // We should set configures for some special codecs.
+                switch (codec->id) {
+                    case AV_CODEC_ID_AAC: // in case of aac encoder, sample format is float
+                        avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
+                        avctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
+                        avctx->channel_layout = av_get_default_channel_layout(avctx->channels);
+
+                        LOG_INFO("aac encoder!! channels %d channel_layout %lld\n", avctx->channels, avctx->channel_layout);
+                        avctx->channel_layout = av_get_default_channel_layout(avctx->channels);
+                        break;
+                    case AV_CODEC_ID_H264:
+                        avctx->flags = 0;
+                        /* if you set this, you can encode AVC format
+                        avctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
+                        */
+                        avctx->flags |= CODEC_FLAG_CLOSED_GOP;
+                        avctx->flags |= CODEC_FLAG_LOOP_FILTER;
+
+                        avctx->bit_rate = 0;
+                        avctx->qmin = 1;
+                        avctx->qmax = 45;
+                        avctx->qcompress = 0.49;
+                        av_dict_set(&opts, "aud", "1" , 0);
+                        break;
+                    default:
+                        break;
+                }
             }
-
             LOG_TRACE("audio sample format %d\n", avctx->sample_fmt);
             LOG_TRACE("strict_std_compliance %d\n", avctx->strict_std_compliance);
 
-            ret = avcodec_open2(avctx, codec, NULL);
+            ret = avcodec_open2(avctx, codec, &opts);
             LOG_INFO("avcodec_open. ret 0x%x ctx_id %d\n", ret, ctx_id);
             LOG_INFO("channels %d sample_rate %d sample_fmt %d "
                 "channel_layout %lld frame_size %d\n",