From aacaf1bb3679bd0de6c82a952334d6679f00aba2 Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Wed, 24 Apr 2013 11:37:19 +0700 Subject: [PATCH 1/9] OMXCodec: Re-implement requires-flush-before-shutdown quirk Support is already there, but is not in the codec quirk reading list. Re-implement it as required by Broadcom's OMX Change-Id: I1beac06af8118dcf0c248b631bc8e6dbbab2c1d5 --- media/libstagefright/OMXCodec.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp index 5d255e4..5b84627 100644 --- a/media/libstagefright/OMXCodec.cpp +++ b/media/libstagefright/OMXCodec.cpp @@ -372,6 +372,9 @@ uint32_t OMXCodec::getComponentQuirks( if (info->hasQuirk("output-buffers-are-unreadable")) { quirks |= kOutputBuffersAreUnreadable; } + if (info->hasQuirk("requires-flush-before-shutdown")) { + quirks |= kRequiresFlushBeforeShutdown; + } if (info->hasQuirk("requies-loaded-to-idle-after-allocation")) { quirks |= kRequiresLoadedToIdleAfterAllocation; } -- 2.3.2 (Apple Git-55) From 3dff91d1327ea328ddcd967a3d9432786695f7fc Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Tue, 17 Dec 2013 13:15:52 +0700 Subject: [PATCH 2/9] OMXCodec: set default input buffer size Broadcom OMX only set the buffer size to 65536 by default which is not enough for higher bitrate video (This patch has been adapted for Lollipop) Change-Id: I74372f3d821e41feb38b9bc0cca4ef56aa019493 --- media/libstagefright/ACodec.cpp | 13 +++++++++++++ media/libstagefright/OMXCodec.cpp | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index 02bb7c4..3e945ce 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -1694,6 +1694,19 @@ status_t ACodec::configureCodec( } else if (!strcmp("OMX.Nvidia.aac.decoder", mComponentName.c_str())) { err = setMinBufferSize(kPortIndexInput, 8192); // XXX } +// Capri's OMX fail to set a reasonable default size from width and height +#ifdef CAPRI_HWC + else if (!strncmp(mComponentName.c_str(), "OMX.BRCM.vc4.decoder.", 21)) { + int32_t width; + int32_t height; + if (msg->findInt32("width", &width) && msg->findInt32("height", &height)) { + setMinBufferSize(kPortIndexInput, (width * height * 3) / 2); + } else { + ALOGE("Failed to set min buffer size"); + } + } +#endif + CHECK_EQ(getPortFormat(kPortIndexInput, inputFormat), (status_t)OK); CHECK_EQ(getPortFormat(kPortIndexOutput, outputFormat), (status_t)OK); diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp index 5b84627..e9b52bb 100644 --- a/media/libstagefright/OMXCodec.cpp +++ b/media/libstagefright/OMXCodec.cpp @@ -914,6 +914,18 @@ status_t OMXCodec::configureCodec(const sp &meta) { if (meta->findInt32(kKeyMaxInputSize, &maxInputSize)) { setMinBufferSize(kPortIndexInput, (OMX_U32)maxInputSize); } +// Capri's OMX fail to set a reasonable default size from width and height +#ifdef CAPRI_HWC + else if (!strncmp(mComponentName, "OMX.BRCM.vc4.decoder.", 21)) { + int32_t width; + int32_t height; + if (meta->findInt32(kKeyWidth, &width) && meta->findInt32(kKeyHeight, &height)) { + setMinBufferSize(kPortIndexInput, (width * height * 3) / 2); + } else { + ALOGE("Failed to set min buffer size"); + } + } +#endif initOutputFormat(meta); -- 2.3.2 (Apple Git-55) From 466a2e77e547c3be26be0b5339b5963a498e0bd9 Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Wed, 19 Nov 2014 20:33:58 +0700 Subject: [PATCH 3/9] ACodec: skip port index checking on vc4 encoder Change-Id: I3fe742a8ec4b7f9bc0c4e5f0825fd3b88965a95e --- media/libstagefright/ACodec.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index 3e945ce..271c790 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -3388,6 +3388,11 @@ status_t ACodec::getPortFormat(OMX_U32 portIndex, sp ¬ify) { mNode, OMX_IndexParamPortDefinition, &def, sizeof(def)), (status_t)OK); +#ifdef CAPRI_HWC + if (strncmp(mComponentName.c_str(), "OMX.BRCM.vc4.encoder.", 21) != 0) + // Skip checking on vc4 encoder. It will return the incorrect + // port index, but correct parameters. +#endif CHECK_EQ((int)def.eDir, (int)(portIndex == kPortIndexOutput ? OMX_DirOutput : OMX_DirInput)); -- 2.3.2 (Apple Git-55) From 65a1ec9800a0e90fbef01e69784640f41aaf46b4 Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Sun, 23 Nov 2014 17:27:20 +0700 Subject: [PATCH 4/9] ACodec: Don't trust provided width/height when setting input buffer size They are bogus Change-Id: I202b291a84d2f9a8c29aa2177ba52a0465f39deb --- media/libstagefright/ACodec.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index 271c790..b65dd0c 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -1697,13 +1697,9 @@ status_t ACodec::configureCodec( // Capri's OMX fail to set a reasonable default size from width and height #ifdef CAPRI_HWC else if (!strncmp(mComponentName.c_str(), "OMX.BRCM.vc4.decoder.", 21)) { - int32_t width; - int32_t height; - if (msg->findInt32("width", &width) && msg->findInt32("height", &height)) { - setMinBufferSize(kPortIndexInput, (width * height * 3) / 2); - } else { - ALOGE("Failed to set min buffer size"); - } + // We cannot trust the width/height from the message + // so just use 1920x1080 + setMinBufferSize(kPortIndexInput, (1920 * 1080 * 3) / 2); } #endif -- 2.3.2 (Apple Git-55) From cd144785beba3fc8fbbed55877bdbdca9ba7f626 Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Fri, 28 Nov 2014 21:07:59 +0700 Subject: [PATCH 5/9] AudioFlinger: i9082: HACK: disable stereo record Stereo record causes audio to speed up x2 for some reason. Record in mono and let AudioFlinger resample to stereo (we only have one mic anyway) Change-Id: I59236addc022186fa35bd3b3914f42709c2318de --- services/audioflinger/AudioFlinger.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 0b2943c..fa3fbf1 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -2248,6 +2248,12 @@ sp AudioFlinger::openInput_l(audio_module_handle_t m audio_config_t halconfig = *config; audio_hw_device_t *inHwHal = inHwDev->hwDevice(); audio_stream_in_t *inStream = NULL; + +#ifdef CAPRI_HWC + ALOGD("Forcing channel mask to mono on capri"); + halconfig.channel_mask = AUDIO_CHANNEL_IN_MONO; +#endif + status_t status = inHwHal->open_input_stream(inHwHal, *input, device, &halconfig, &inStream, flags, address.string(), source); ALOGV("openInput_l() openInputStream returned input %p, SamplingRate %d" -- 2.3.2 (Apple Git-55) From c3512ea44f06c667a1dda218726b18027d4e7b58 Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Wed, 10 Dec 2014 17:38:10 +0700 Subject: [PATCH 6/9] AudioFlinger: i9082: HACK: force audio to 48 KHz Let surfaceflinger do all the resampling instead of the audio HAL Don't know if it fixes anything, but worth a try Change-Id: I0113831464f2f64c26a9c93bba8fe6b8229b09b4 --- services/audioflinger/AudioFlinger.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index fa3fbf1..f4c6a2a 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -2250,8 +2250,9 @@ sp AudioFlinger::openInput_l(audio_module_handle_t m audio_stream_in_t *inStream = NULL; #ifdef CAPRI_HWC - ALOGD("Forcing channel mask to mono on capri"); + ALOGD("Forcing input to mono 48K on capri"); halconfig.channel_mask = AUDIO_CHANNEL_IN_MONO; + halconfig.sample_rate = 48000; #endif status_t status = inHwHal->open_input_stream(inHwHal, *input, device, &halconfig, -- 2.3.2 (Apple Git-55) From 17071cbba07190b405bc1c6684852423b5cf5a8a Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Tue, 16 Dec 2014 21:12:22 +0700 Subject: [PATCH 7/9] stagefright: i9082: don't allocate too many extra buffers Too many extra buffers (for a total of 8) causes random video freezes and freezes on rotation Change-Id: Idfe85f3cd77d6aa5422073857ceecec902e3ca68 --- media/libstagefright/ACodec.cpp | 4 ++++ media/libstagefright/OMXCodec.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index b65dd0c..ce1c1cc 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -787,7 +787,11 @@ status_t ACodec::configureOutputBuffersFromNativeWindow( // This check was present in KitKat. if (def.nBufferCountActual < def.nBufferCountMin + *minUndequeuedBuffers) { #endif +#ifdef CAPRI_HWC + for (OMX_U32 extraBuffers = 1; /* condition inside loop */; extraBuffers--) { +#else for (OMX_U32 extraBuffers = 2 + 1; /* condition inside loop */; extraBuffers--) { +#endif OMX_U32 newBufferCount = def.nBufferCountMin + *minUndequeuedBuffers + extraBuffers; def.nBufferCountActual = newBufferCount; diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp index e9b52bb..ba96ce5 100644 --- a/media/libstagefright/OMXCodec.cpp +++ b/media/libstagefright/OMXCodec.cpp @@ -2325,7 +2325,11 @@ status_t OMXCodec::allocateOutputBuffersFromNativeWindow() { // This check was present in KitKat. if (def.nBufferCountActual < def.nBufferCountMin + minUndequeuedBufs) { #endif +#ifdef CAPRI_HWC + for (OMX_U32 extraBuffers = 1; /* condition inside loop */; extraBuffers--) { +#else for (OMX_U32 extraBuffers = 2 + 1; /* condition inside loop */; extraBuffers--) { +#endif OMX_U32 newBufferCount = def.nBufferCountMin + minUndequeuedBufs + extraBuffers; def.nBufferCountActual = newBufferCount; -- 2.3.2 (Apple Git-55) From 45fb4ec21a6f02abfbeed4ed34fadd382b891d17 Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Sat, 20 Dec 2014 19:09:59 +0700 Subject: [PATCH 8/9] stagefright: CAPRI_HWC: fix for screen recording Change-Id: Ib8a677eb1ecabc30efe163faa9b209f4db966437 --- media/libstagefright/omx/GraphicBufferSource.cpp | 2 ++ media/libstagefright/omx/OMXNodeInstance.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/media/libstagefright/omx/GraphicBufferSource.cpp b/media/libstagefright/omx/GraphicBufferSource.cpp index 3e70956..d600573 100644 --- a/media/libstagefright/omx/GraphicBufferSource.cpp +++ b/media/libstagefright/omx/GraphicBufferSource.cpp @@ -269,12 +269,14 @@ void GraphicBufferSource::codecBufferEmptied(OMX_BUFFERHEADERTYPE* header) { } else if (type == kMetadataBufferTypeGraphicBuffer) { GraphicBuffer *buffer; memcpy(&buffer, data + 4, sizeof(buffer)); +#ifndef CAPRI_HWC if (buffer != codecBuffer.mGraphicBuffer.get()) { // should never happen ALOGE("codecBufferEmptied: buffer is %p, expected %p", buffer, codecBuffer.mGraphicBuffer.get()); CHECK(!"codecBufferEmptied: mismatched buffer"); } +#endif } } diff --git a/media/libstagefright/omx/OMXNodeInstance.cpp b/media/libstagefright/omx/OMXNodeInstance.cpp index 8c22255..eaa20c9 100644 --- a/media/libstagefright/omx/OMXNodeInstance.cpp +++ b/media/libstagefright/omx/OMXNodeInstance.cpp @@ -733,9 +733,16 @@ status_t OMXNodeInstance::createInputSurface( CHECK(oerr == OMX_ErrorNone); if (def.format.video.eColorFormat != OMX_COLOR_FormatAndroidOpaque) { +#ifdef CAPRI_HWC + // VC Encoder change OMX_COLOR_FormatAndroidOpaque to 0x7F000005 + if (def.format.video.eColorFormat != 0x7F000005) { +#endif ALOGE("createInputSurface requires COLOR_FormatSurface " "(AndroidOpaque) color format"); return INVALID_OPERATION; +#ifdef CAPRI_HWC + } +#endif } GraphicBufferSource* bufferSource = new GraphicBufferSource( -- 2.3.2 (Apple Git-55) From 906b861985f0d7c910b6e33038f72a29b3d715d8 Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Sun, 21 Dec 2014 15:25:33 +0700 Subject: [PATCH 9/9] stagefright: CAPRI_HWC: fix for miracast Our encoder does not support OMX_Video_ControlRateConstant Change-Id: I5f98f00406a6b28c1a2a1862fbcefa2fdd9055d6 --- media/libstagefright/ACodec.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index ce1c1cc..9b6874c 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -2566,7 +2566,13 @@ static OMX_U32 setPFramesSpacing(int32_t iFramesInterval, int32_t frameRate) { return ret; } -static OMX_VIDEO_CONTROLRATETYPE getBitrateMode(const sp &msg) { +static OMX_VIDEO_CONTROLRATETYPE getBitrateMode(const sp &msg, const AString &name) { +#ifdef CAPRI_HWC + // vc4 encoder only supports VBR + if (strncmp(name.c_str(), "OMX.BRCM.vc4.encoder.", 21) == 0) { + return OMX_Video_ControlRateVariable; + } +#endif int32_t tmp; if (!msg->findInt32("bitrate-mode", &tmp)) { return OMX_Video_ControlRateVariable; @@ -2582,7 +2588,7 @@ status_t ACodec::setupMPEG4EncoderParameters(const sp &msg) { return INVALID_OPERATION; } - OMX_VIDEO_CONTROLRATETYPE bitrateMode = getBitrateMode(msg); + OMX_VIDEO_CONTROLRATETYPE bitrateMode = getBitrateMode(msg, mComponentName); float frameRate; if (!msg->findFloat("frame-rate", &frameRate)) { @@ -2664,7 +2670,7 @@ status_t ACodec::setupH263EncoderParameters(const sp &msg) { return INVALID_OPERATION; } - OMX_VIDEO_CONTROLRATETYPE bitrateMode = getBitrateMode(msg); + OMX_VIDEO_CONTROLRATETYPE bitrateMode = getBitrateMode(msg, mComponentName); float frameRate; if (!msg->findFloat("frame-rate", &frameRate)) { @@ -2792,7 +2798,7 @@ status_t ACodec::setupAVCEncoderParameters(const sp &msg) { return INVALID_OPERATION; } - OMX_VIDEO_CONTROLRATETYPE bitrateMode = getBitrateMode(msg); + OMX_VIDEO_CONTROLRATETYPE bitrateMode = getBitrateMode(msg, mComponentName); float frameRate; if (!msg->findFloat("frame-rate", &frameRate)) { @@ -2907,7 +2913,7 @@ status_t ACodec::setupHEVCEncoderParameters(const sp &msg) { return INVALID_OPERATION; } - OMX_VIDEO_CONTROLRATETYPE bitrateMode = getBitrateMode(msg); + OMX_VIDEO_CONTROLRATETYPE bitrateMode = getBitrateMode(msg, mComponentName); float frameRate; if (!msg->findFloat("frame-rate", &frameRate)) { @@ -2974,7 +2980,7 @@ status_t ACodec::setupVPXEncoderParameters(const sp &msg) { } msg->findInt32("i-frame-interval", &iFrameInterval); - OMX_VIDEO_CONTROLRATETYPE bitrateMode = getBitrateMode(msg); + OMX_VIDEO_CONTROLRATETYPE bitrateMode = getBitrateMode(msg, mComponentName); float frameRate; if (!msg->findFloat("frame-rate", &frameRate)) { -- 2.3.2 (Apple Git-55)