summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRockchip2015-10-16 10:28:39 +0800
committerRockchip2015-10-16 10:28:39 +0800
commitb7cea21aa2c9fe2457ac3899d49c7a2340580f30 (patch)
tree9a3d7086a24862de3e7417e99b1cdbc125ebcf96
parentc86ef35845c05a89cb58ae93784f8a5fff040c37 (diff)
sf:add interface to control encorder frameRate for screenrecord
-rwxr-xr-xmedia/libstagefright/ACodec.cpp2
-rwxr-xr-x[-rw-r--r--]media/libstagefright/include/OMXNodeInstance.h214
-rwxr-xr-x[-rw-r--r--]media/libstagefright/omx/GraphicBufferSource.cpp37
-rwxr-xr-x[-rw-r--r--]media/libstagefright/omx/GraphicBufferSource.h4
-rwxr-xr-xmedia/libstagefright/omx/OMXNodeInstance.cpp15
5 files changed, 54 insertions, 218 deletions
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index fc7fe65..ff9fa50 100755
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -2971,7 +2971,7 @@ status_t ACodec::setupAVCEncoderParameters(const sp<AMessage> &msg) {
h264type.bUseHadamard = OMX_TRUE;
h264type.nRefFrames = 1;
h264type.nBFrames = 0;
- h264type.nPFrames = setPFramesSpacing(iFrameInterval, frameRate);
+ h264type.nPFrames = (OMX_U32)frameRate; //setPFramesSpacing(iFrameInterval, frameRate);
if (h264type.nPFrames == 0) {
h264type.nAllowedPictureTypes = OMX_VIDEO_PictureTypeI;
}
diff --git a/media/libstagefright/include/OMXNodeInstance.h b/media/libstagefright/include/OMXNodeInstance.h
index 104dcfc..e69de29 100644..100755
--- a/media/libstagefright/include/OMXNodeInstance.h
+++ b/media/libstagefright/include/OMXNodeInstance.h
@@ -1,214 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef OMX_NODE_INSTANCE_H_
-
-#define OMX_NODE_INSTANCE_H_
-
-#include "OMX.h"
-
-#include <utils/RefBase.h>
-#include <utils/threads.h>
-
-namespace android {
-
-class IOMXObserver;
-struct OMXMaster;
-struct GraphicBufferSource;
-
-struct OMXNodeInstance {
- OMXNodeInstance(
- OMX *owner, const sp<IOMXObserver> &observer, const char *name);
-
- void setHandle(OMX::node_id node_id, OMX_HANDLETYPE handle);
-
- OMX *owner();
- sp<IOMXObserver> observer();
- OMX::node_id nodeID();
-
- status_t freeNode(OMXMaster *master);
-
- status_t sendCommand(OMX_COMMANDTYPE cmd, OMX_S32 param);
- status_t getParameter(OMX_INDEXTYPE index, void *params, size_t size);
-
- status_t setParameter(
- OMX_INDEXTYPE index, const void *params, size_t size);
-
- status_t getConfig(OMX_INDEXTYPE index, void *params, size_t size);
- status_t setConfig(OMX_INDEXTYPE index, const void *params, size_t size);
-
- status_t getState(OMX_STATETYPE* state);
-
- status_t enableGraphicBuffers(OMX_U32 portIndex, OMX_BOOL enable);
-
- status_t getGraphicBufferUsage(OMX_U32 portIndex, OMX_U32* usage);
-
- status_t storeMetaDataInBuffers(OMX_U32 portIndex, OMX_BOOL enable);
-
- status_t prepareForAdaptivePlayback(
- OMX_U32 portIndex, OMX_BOOL enable,
- OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight);
-
- status_t configureVideoTunnelMode(
- OMX_U32 portIndex, OMX_BOOL tunneled,
- OMX_U32 audioHwSync, native_handle_t **sidebandHandle);
-
- status_t useBuffer(
- OMX_U32 portIndex, const sp<IMemory> &params,
- OMX::buffer_id *buffer);
-
- status_t useGraphicBuffer(
- OMX_U32 portIndex, const sp<GraphicBuffer> &graphicBuffer,
- OMX::buffer_id *buffer);
-
- status_t updateGraphicBufferInMeta(
- OMX_U32 portIndex, const sp<GraphicBuffer> &graphicBuffer,
- OMX::buffer_id buffer);
-
- status_t createInputSurface(
- OMX_U32 portIndex, sp<IGraphicBufferProducer> *bufferProducer);
-
- status_t signalEndOfInputStream();
-
- status_t allocateBuffer(
- OMX_U32 portIndex, size_t size, OMX::buffer_id *buffer,
- void **buffer_data);
-
- status_t allocateBufferWithBackup(
- OMX_U32 portIndex, const sp<IMemory> &params,
- OMX::buffer_id *buffer);
-
- status_t freeBuffer(OMX_U32 portIndex, OMX::buffer_id buffer);
-
- status_t fillBuffer(OMX::buffer_id buffer);
-
- status_t emptyBuffer(
- OMX::buffer_id buffer,
- OMX_U32 rangeOffset, OMX_U32 rangeLength,
- OMX_U32 flags, OMX_TICKS timestamp);
-
- status_t emptyDirectBuffer(
- OMX_BUFFERHEADERTYPE *header,
- OMX_U32 rangeOffset, OMX_U32 rangeLength,
- OMX_U32 flags, OMX_TICKS timestamp);
-
- status_t getExtensionIndex(
- const char *parameterName, OMX_INDEXTYPE *index);
-
- status_t setInternalOption(
- OMX_U32 portIndex,
- IOMX::InternalOptionType type,
- const void *data,
- size_t size);
-
- void onMessage(const omx_message &msg);
- void onObserverDied(OMXMaster *master);
- void onGetHandleFailed();
- void onEvent(OMX_EVENTTYPE event, OMX_U32 arg1, OMX_U32 arg2);
-
- static OMX_CALLBACKTYPE kCallbacks;
-
-private:
- Mutex mLock;
-
- OMX *mOwner;
- OMX::node_id mNodeID;
- OMX_HANDLETYPE mHandle;
- sp<IOMXObserver> mObserver;
- bool mDying;
-
- // Lock only covers mGraphicBufferSource. We can't always use mLock
- // because of rare instances where we'd end up locking it recursively.
- Mutex mGraphicBufferSourceLock;
- // Access this through getGraphicBufferSource().
- sp<GraphicBufferSource> mGraphicBufferSource;
-
-
- struct ActiveBuffer {
- OMX_U32 mPortIndex;
- OMX::buffer_id mID;
- };
- Vector<ActiveBuffer> mActiveBuffers;
-#ifdef __LP64__
- Mutex mBufferIDLock;
- uint32_t mBufferIDCount;
- KeyedVector<OMX::buffer_id, OMX_BUFFERHEADERTYPE *> mBufferIDToBufferHeader;
- KeyedVector<OMX_BUFFERHEADERTYPE *, OMX::buffer_id> mBufferHeaderToBufferID;
-#endif
-
- // For debug support
- char *mName;
- int DEBUG;
- size_t mNumPortBuffers[2]; // modified under mLock, read outside for debug
- Mutex mDebugLock;
- // following are modified and read under mDebugLock
- int DEBUG_BUMP;
- SortedVector<OMX_BUFFERHEADERTYPE *> mInputBuffersWithCodec, mOutputBuffersWithCodec;
- size_t mDebugLevelBumpPendingBuffers[2];
- void bumpDebugLevel_l(size_t numInputBuffers, size_t numOutputBuffers);
- void unbumpDebugLevel_l(size_t portIndex);
-
- ~OMXNodeInstance();
-
- void addActiveBuffer(OMX_U32 portIndex, OMX::buffer_id id);
- void removeActiveBuffer(OMX_U32 portIndex, OMX::buffer_id id);
- void freeActiveBuffers();
-
- // For buffer id management
- OMX::buffer_id makeBufferID(OMX_BUFFERHEADERTYPE *bufferHeader);
- OMX_BUFFERHEADERTYPE *findBufferHeader(OMX::buffer_id buffer);
- OMX::buffer_id findBufferID(OMX_BUFFERHEADERTYPE *bufferHeader);
- void invalidateBufferID(OMX::buffer_id buffer);
-
- status_t useGraphicBuffer2_l(
- OMX_U32 portIndex, const sp<GraphicBuffer> &graphicBuffer,
- OMX::buffer_id *buffer);
- static OMX_ERRORTYPE OnEvent(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_IN OMX_PTR pAppData,
- OMX_IN OMX_EVENTTYPE eEvent,
- OMX_IN OMX_U32 nData1,
- OMX_IN OMX_U32 nData2,
- OMX_IN OMX_PTR pEventData);
-
- static OMX_ERRORTYPE OnEmptyBufferDone(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_IN OMX_PTR pAppData,
- OMX_IN OMX_BUFFERHEADERTYPE *pBuffer);
-
- static OMX_ERRORTYPE OnFillBufferDone(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_IN OMX_PTR pAppData,
- OMX_IN OMX_BUFFERHEADERTYPE *pBuffer);
-
- status_t storeMetaDataInBuffers_l(
- OMX_U32 portIndex, OMX_BOOL enable,
- OMX_BOOL useGraphicBuffer, OMX_BOOL *usingGraphicBufferInMeta);
-
- status_t emptyBuffer_l(
- OMX_BUFFERHEADERTYPE *header,
- OMX_U32 flags, OMX_TICKS timestamp, intptr_t debugAddr);
-
- sp<GraphicBufferSource> getGraphicBufferSource();
- void setGraphicBufferSource(const sp<GraphicBufferSource>& bufferSource);
-
- OMXNodeInstance(const OMXNodeInstance &);
- OMXNodeInstance &operator=(const OMXNodeInstance &);
-};
-
-} // namespace android
-
-#endif // OMX_NODE_INSTANCE_H_
diff --git a/media/libstagefright/omx/GraphicBufferSource.cpp b/media/libstagefright/omx/GraphicBufferSource.cpp
index 44c7edc..2438bff 100644..100755
--- a/media/libstagefright/omx/GraphicBufferSource.cpp
+++ b/media/libstagefright/omx/GraphicBufferSource.cpp
@@ -100,9 +100,17 @@ GraphicBufferSource::GraphicBufferSource(OMXNodeInstance* nodeInstance,
return;
}
+ interval_time = ms2ns(1000) / 60;
+ next_time = 0;
CHECK(mInitCheck == NO_ERROR);
}
+void GraphicBufferSource::setFrameRate(int32_t frameRate){
+ interval_time = ms2ns(1000) / frameRate;
+ next_time = 0;
+ ALOGD(" danielycycyc GraphicBufferSource::setFrameRate()_%d interval_time = %lld(%lld) mFrameRate = %d\n",
+ __LINE__, ns2ms(interval_time), interval_time, frameRate);
+}
GraphicBufferSource::~GraphicBufferSource() {
ALOGV("~GraphicBufferSource");
if (mConsumer != NULL) {
@@ -446,7 +454,34 @@ bool GraphicBufferSource::fillCodecBuffer_l() {
if (mSkipFramesBeforeNs > 0) {
item.mTimestamp -= mSkipFramesBeforeNs;
}
- err = submitBuffer_l(item, cbi);
+#if 0
+ err = submitBuffer_l(item, cbi);
+#else
+ nsecs_t now_t = systemTime();
+ bool bSubmitB = false;
+ if(next_time == 0){
+ next_time = now_t + interval_time;
+ bSubmitB = true;
+ }else{
+ if(now_t >= next_time){
+ nsecs_t diff_t = now_t - next_time;
+ nsecs_t multiple = diff_t / interval_time;
+ if(multiple > 0){
+ next_time += (interval_time * (multiple + 1));
+ }else{
+ next_time += interval_time;
+ }
+ bSubmitB = true;
+ }
+ }
+ //ALOGD(" danielycycyc GraphicBufferSource::fillCodecBuffer_l()__%d, now_t = %lld next_time = %lld bSubmitB = %d\n ",
+ // __LINE__, ns2ms(now_t), ns2ms(next_time), bSubmitB);
+ if(bSubmitB){
+ err = submitBuffer_l(item, cbi);
+ }else{
+ err = BAD_VALUE;
+ }
+#endif
}
if (err != OK) {
diff --git a/media/libstagefright/omx/GraphicBufferSource.h b/media/libstagefright/omx/GraphicBufferSource.h
index c8e3775..7f477f5 100644..100755
--- a/media/libstagefright/omx/GraphicBufferSource.h
+++ b/media/libstagefright/omx/GraphicBufferSource.h
@@ -129,7 +129,7 @@ public:
// Sets the start time us (in system time), samples before which should
// be dropped and not submitted to encoder
void setSkipFramesBeforeUs(int64_t startTimeUs);
-
+ void setFrameRate(int32_t frameRate);
protected:
// BufferQueue::ConsumerListener interface, called when a new frame of
// data is available. If we're executing and a codec buffer is
@@ -276,6 +276,8 @@ private:
void onMessageReceived(const sp<AMessage> &msg);
+ nsecs_t next_time;
+ nsecs_t interval_time;
DISALLOW_EVIL_CONSTRUCTORS(GraphicBufferSource);
};
diff --git a/media/libstagefright/omx/OMXNodeInstance.cpp b/media/libstagefright/omx/OMXNodeInstance.cpp
index a03c00f..20ae181 100755
--- a/media/libstagefright/omx/OMXNodeInstance.cpp
+++ b/media/libstagefright/omx/OMXNodeInstance.cpp
@@ -169,7 +169,8 @@ OMXNodeInstance::OMXNodeInstance(
mNodeID(0),
mHandle(NULL),
mObserver(observer),
- mDying(false)
+ mDying(false),
+ mFrameRate(0)
#ifdef __LP64__
, mBufferIDCount(0)
#endif
@@ -206,6 +207,10 @@ void OMXNodeInstance::setGraphicBufferSource(
Mutex::Autolock autoLock(mGraphicBufferSourceLock);
CLOG_INTERNAL(setGraphicBufferSource, "%p", bufferSource.get());
mGraphicBufferSource = bufferSource;
+ if(mFrameRate > 0 && mGraphicBufferSource != NULL){
+ ALOGD(" <%s>_%d mFrameRate = %d \n", __func__, __LINE__, mFrameRate);
+ mGraphicBufferSource->setFrameRate(mFrameRate);
+ }
}
OMX *OMXNodeInstance::owner() {
@@ -394,6 +399,14 @@ status_t OMXNodeInstance::setParameter(
OMX_ERRORTYPE err = OMX_SetParameter(
mHandle, index, const_cast<void *>(params));
CLOG_IF_ERROR(setParameter, err, "%s(%#x)", asString(extIndex), index);
+ if(index == OMX_IndexParamVideoAvc && params != NULL){
+ OMX_VIDEO_PARAM_AVCTYPE * h264type = (OMX_VIDEO_PARAM_AVCTYPE *)params;
+ mFrameRate = h264type->nPFrames;
+ if(mFrameRate > 0 && mGraphicBufferSource != NULL){
+ ALOGD(" <%s>_%d mFrameRate = %d \n", __func__, __LINE__, mFrameRate);
+ mGraphicBufferSource->setFrameRate(mFrameRate);
+ }
+ }
return StatusFromOMXError(err);
}