本文整理汇总了C++中OMXClient类的典型用法代码示例。如果您正苦于以下问题:C++ OMXClient类的具体用法?C++ OMXClient怎么用?C++ OMXClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OMXClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AudioSource
sp<MediaSource> StagefrightRecorder::createAudioSource() {
sp<AudioSource> audioSource =
new AudioSource(
mAudioSource,
mSampleRate,
mAudioChannels);
status_t err = audioSource->initCheck();
if (err != OK) {
LOGE("audio source is not initialized");
return NULL;
}
sp<MetaData> encMeta = new MetaData;
const char *mime;
switch (mAudioEncoder) {
case AUDIO_ENCODER_AMR_NB:
case AUDIO_ENCODER_DEFAULT:
mime = MEDIA_MIMETYPE_AUDIO_AMR_NB;
break;
case AUDIO_ENCODER_AMR_WB:
mime = MEDIA_MIMETYPE_AUDIO_AMR_WB;
break;
case AUDIO_ENCODER_AAC:
mime = MEDIA_MIMETYPE_AUDIO_AAC;
break;
default:
LOGE("Unknown audio encoder: %d", mAudioEncoder);
return NULL;
}
encMeta->setCString(kKeyMIMEType, mime);
int32_t maxInputSize;
CHECK(audioSource->getFormat()->findInt32(
kKeyMaxInputSize, &maxInputSize));
encMeta->setInt32(kKeyMaxInputSize, maxInputSize);
encMeta->setInt32(kKeyChannelCount, mAudioChannels);
encMeta->setInt32(kKeySampleRate, mSampleRate);
encMeta->setInt32(kKeyBitRate, mAudioBitRate);
if (mAudioTimeScale > 0) {
encMeta->setInt32(kKeyTimeScale, mAudioTimeScale);
}
OMXClient client;
CHECK_EQ(client.connect(), OK);
sp<MediaSource> audioEncoder =
OMXCodec::Create(client.interface(), encMeta,
true /* createEncoder */, audioSource);
mAudioSourceNode = audioSource;
return audioEncoder;
}
示例2: main
int main(int argc, char **argv) {
android::ProcessState::self()->startThreadPool();
OMXClient client;
CHECK_EQ(client.connect(), OK);
const int32_t kSampleRate = 22050;
const int32_t kNumChannels = 2;
sp<MediaSource> audioSource = new SineSource(kSampleRate, kNumChannels);
#if 0
sp<MediaPlayerBase::AudioSink> audioSink;
AudioPlayer *player = new AudioPlayer(audioSink);
player->setSource(audioSource);
player->start();
sleep(10);
player->stop();
#endif
sp<MetaData> encMeta = new MetaData;
encMeta->setCString(kKeyMIMEType,
1 ? MEDIA_MIMETYPE_AUDIO_AMR_WB : MEDIA_MIMETYPE_AUDIO_AAC);
encMeta->setInt32(kKeySampleRate, kSampleRate);
encMeta->setInt32(kKeyChannelCount, kNumChannels);
encMeta->setInt32(kKeyMaxInputSize, 8192);
sp<MediaSource> encoder =
OMXCodec::Create(client.interface(), encMeta, true, audioSource);
encoder->start();
int32_t n = 0;
status_t err;
MediaBuffer *buffer;
while ((err = encoder->read(&buffer)) == OK) {
printf(".");
fflush(stdout);
buffer->release();
buffer = NULL;
if (++n == 100) {
break;
}
}
printf("$\n");
encoder->stop();
client.disconnect();
return 0;
}
示例3: PREFIX
OMX_ERRORTYPE PREFIX(OMX_Init)(void)
{
OMXClient client;
if (client.connect() != OK)
return OMX_ErrorUndefined;
if (!ctx)
ctx = new IOMXContext();
ctx->iomx = client.interface();
ctx->iomx->listNodes(&ctx->components);
return OMX_ErrorNone;
}
示例4: getCodecCapabilities
status_t MediaCodecList::getCodecCapabilities(
size_t index, const char *type,
Vector<ProfileLevel> *profileLevels,
Vector<uint32_t> *colorFormats,
uint32_t *flags) const {
profileLevels->clear();
colorFormats->clear();
if (index >= mCodecInfos.size()) {
return -ERANGE;
}
const CodecInfo &info = mCodecInfos.itemAt(index);
OMXClient client;
status_t err = client.connect();
if (err != OK) {
return err;
}
CodecCapabilities caps;
err = QueryCodec(
client.interface(),
info.mName.c_str(), type, info.mIsEncoder, &caps);
if (err != OK) {
return err;
}
for (size_t i = 0; i < caps.mProfileLevels.size(); ++i) {
const CodecProfileLevel &src = caps.mProfileLevels.itemAt(i);
ProfileLevel profileLevel;
profileLevel.mProfile = src.mProfile;
profileLevel.mLevel = src.mLevel;
profileLevels->push(profileLevel);
}
for (size_t i = 0; i < caps.mColorFormats.size(); ++i) {
colorFormats->push(caps.mColorFormats.itemAt(i));
}
*flags = caps.mFlags;
return OK;
}
示例5: PREFIX
OMX_ERRORTYPE PREFIX(OMX_Init)(void)
{
android_printf("OMX_Init\n");
OMXClient client;
if (client.connect() != OK)
return OMX_ErrorUndefined;
if (!ctx)
ctx = new IOMXContext();
ctx->iomx = client.interface();
ctx->iomx->listNodes(&ctx->components);
for (List<IOMX::ComponentInfo>::iterator it = ctx->components.begin(); it != ctx->components.end(); it++)
{
const IOMX::ComponentInfo &info = *it;
const char* componentName = info.mName.string();
for (List<String8>::const_iterator role_it = info.mRoles.begin(); role_it != info.mRoles.end(); role_it++)
{
const char* componentRole = (*role_it).string();
android_printf("componentName:%s,componentRole:%s\n", componentName, componentRole);
}
}
return OMX_ErrorNone;
}
示例6: PR_NewLogModule
bool OmxDecoder::Init() {
#ifdef PR_LOGGING
if (!gOmxDecoderLog) {
gOmxDecoderLog = PR_NewLogModule("OmxDecoder");
}
#endif
//register sniffers, if they are not registered in this process.
DataSource::RegisterDefaultSniffers();
sp<DataSource> dataSource = new MediaStreamSource(mResource, mDecoder);
if (dataSource->initCheck()) {
NS_WARNING("Initializing DataSource for OMX decoder failed");
return false;
}
mResource->SetReadMode(MediaCacheStream::MODE_METADATA);
sp<MediaExtractor> extractor = MediaExtractor::Create(dataSource);
if (extractor == nullptr) {
NS_WARNING("Could not create MediaExtractor");
return false;
}
ssize_t audioTrackIndex = -1;
ssize_t videoTrackIndex = -1;
const char *audioMime = nullptr;
for (size_t i = 0; i < extractor->countTracks(); ++i) {
sp<MetaData> meta = extractor->getTrackMetaData(i);
int32_t bitRate;
if (!meta->findInt32(kKeyBitRate, &bitRate))
bitRate = 0;
const char *mime;
if (!meta->findCString(kKeyMIMEType, &mime)) {
continue;
}
if (videoTrackIndex == -1 && !strncasecmp(mime, "video/", 6)) {
videoTrackIndex = i;
} else if (audioTrackIndex == -1 && !strncasecmp(mime, "audio/", 6)) {
audioTrackIndex = i;
audioMime = mime;
}
}
if (videoTrackIndex == -1 && audioTrackIndex == -1) {
NS_WARNING("OMX decoder could not find video or audio tracks");
return false;
}
mResource->SetReadMode(MediaCacheStream::MODE_PLAYBACK);
int64_t totalDurationUs = 0;
mNativeWindow = new GonkNativeWindow();
mNativeWindowClient = new GonkNativeWindowClient(mNativeWindow);
// OMXClient::connect() always returns OK and abort's fatally if
// it can't connect.
OMXClient client;
status_t err = client.connect();
NS_ASSERTION(err == OK, "Failed to connect to OMX in mediaserver.");
sp<IOMX> omx = client.interface();
sp<MediaSource> videoTrack;
sp<MediaSource> videoSource;
if (videoTrackIndex != -1 && (videoTrack = extractor->getTrack(videoTrackIndex)) != nullptr) {
// Experience with OMX codecs is that only the HW decoders are
// worth bothering with, at least on the platforms where this code
// is currently used, and for formats this code is currently used
// for (h.264). So if we don't get a hardware decoder, just give
// up.
int flags = kHardwareCodecsOnly;
videoSource = OMXCodec::Create(omx,
videoTrack->getFormat(),
false, // decoder
videoTrack,
nullptr,
flags,
mNativeWindowClient);
if (videoSource == nullptr) {
NS_WARNING("Couldn't create OMX video source");
return false;
}
// Check if this video is sized such that we're comfortable
// possibly using an OMX decoder.
int32_t maxWidth, maxHeight;
char propValue[PROPERTY_VALUE_MAX];
property_get("ro.moz.omx.hw.max_width", propValue, "-1");
maxWidth = atoi(propValue);
property_get("ro.moz.omx.hw.max_height", propValue, "-1");
maxHeight = atoi(propValue);
int32_t width = -1, height = -1;
if (maxWidth > 0 && maxHeight > 0 &&
!(videoSource->getFormat()->findInt32(kKeyWidth, &width) &&
//.........这里部分代码省略.........
示例7: VideoEditorVideoEncoder_getDSI
M4OSA_ERR VideoEditorVideoEncoder_getDSI(M4ENCODER_Context pContext,
sp<MetaData> metaData) {
M4OSA_ERR err = M4NO_ERROR;
VideoEditorVideoEncoder_Context* pEncoderContext = M4OSA_NULL;
status_t result = OK;
int32_t nbBuffer = 0;
int32_t stride = 0;
int32_t height = 0;
int32_t framerate = 0;
int32_t isCodecConfig = 0;
size_t size = 0;
uint32_t codecFlags = 0;
MediaBuffer* inputBuffer = NULL;
MediaBuffer* outputBuffer = NULL;
sp<VideoEditorVideoEncoderSource> encoderSource = NULL;
sp<MediaSource> encoder = NULL;;
OMXClient client;
ALOGV("VideoEditorVideoEncoder_getDSI begin");
// Input parameters check
VIDEOEDITOR_CHECK(M4OSA_NULL != pContext, M4ERR_PARAMETER);
VIDEOEDITOR_CHECK(M4OSA_NULL != metaData.get(), M4ERR_PARAMETER);
pEncoderContext = (VideoEditorVideoEncoder_Context*)pContext;
VIDEOEDITOR_CHECK(CREATED == pEncoderContext->mState, M4ERR_STATE);
// Create the encoder source
encoderSource = VideoEditorVideoEncoderSource::Create(metaData);
VIDEOEDITOR_CHECK(NULL != encoderSource.get(), M4ERR_STATE);
// Connect to the OMX client
result = client.connect();
VIDEOEDITOR_CHECK(OK == result, M4ERR_STATE);
// Create the OMX codec
// VIDEOEDITOR_FORCECODEC MUST be defined here
codecFlags |= OMXCodec::VIDEOEDITOR_FORCECODEC;
encoder = OMXCodec::Create(client.interface(), metaData, true,
encoderSource, NULL, codecFlags);
VIDEOEDITOR_CHECK(NULL != encoder.get(), M4ERR_STATE);
/**
* Send fake frames and retrieve the DSI
*/
// Send a fake frame to the source
metaData->findInt32(kKeyStride, &stride);
metaData->findInt32(kKeyHeight, &height);
metaData->findInt32(kKeySampleRate, &framerate);
size = (size_t)(stride*height*3)/2;
inputBuffer = new MediaBuffer(size);
inputBuffer->meta_data()->setInt64(kKeyTime, 0);
nbBuffer = encoderSource->storeBuffer(inputBuffer);
encoderSource->storeBuffer(NULL); // Signal EOS
// Call read once to get the DSI
result = encoder->start();;
VIDEOEDITOR_CHECK(OK == result, M4ERR_STATE);
result = encoder->read(&outputBuffer, NULL);
VIDEOEDITOR_CHECK(OK == result, M4ERR_STATE);
VIDEOEDITOR_CHECK(outputBuffer->meta_data()->findInt32(
kKeyIsCodecConfig, &isCodecConfig) && isCodecConfig, M4ERR_STATE);
VIDEOEDITOR_CHECK(M4OSA_NULL == pEncoderContext->mHeader.pBuf, M4ERR_STATE);
if ( M4ENCODER_kH264 == pEncoderContext->mFormat ) {
// For H264, format the DSI
result = buildAVCCodecSpecificData(
(uint8_t**)(&(pEncoderContext->mHeader.pBuf)),
(size_t*)(&(pEncoderContext->mHeader.Size)),
(const uint8_t*)outputBuffer->data() + outputBuffer->range_offset(),
outputBuffer->range_length(), encoder->getFormat().get());
outputBuffer->release();
VIDEOEDITOR_CHECK(OK == result, M4ERR_STATE);
} else {
// For MPEG4, just copy the DSI
pEncoderContext->mHeader.Size =
(M4OSA_UInt32)outputBuffer->range_length();
SAFE_MALLOC(pEncoderContext->mHeader.pBuf, M4OSA_Int8,
pEncoderContext->mHeader.Size, "Encoder header");
memcpy((void *)pEncoderContext->mHeader.pBuf,
(void *)((M4OSA_MemAddr8)(outputBuffer->data())+outputBuffer->range_offset()),
pEncoderContext->mHeader.Size);
outputBuffer->release();
}
result = encoder->stop();
VIDEOEDITOR_CHECK(OK == result, M4ERR_STATE);
cleanUp:
// Destroy the graph
if ( encoder != NULL ) { encoder.clear(); }
client.disconnect();
if ( encoderSource != NULL ) { encoderSource.clear(); }
if ( M4NO_ERROR == err ) {
ALOGV("VideoEditorVideoEncoder_getDSI no error");
} else {
ALOGV("VideoEditorVideoEncoder_getDSI ERROR 0x%X", err);
}
ALOGV("VideoEditorVideoEncoder_getDSI end");
return err;
}
示例8: NS_ASSERTION
bool OmxDecoder::AllocateMediaResources()
{
if ((mVideoTrack != nullptr) && (mVideoSource == nullptr)) {
// OMXClient::connect() always returns OK and abort's fatally if
// it can't connect.
OMXClient client;
DebugOnly<status_t> err = client.connect();
NS_ASSERTION(err == OK, "Failed to connect to OMX in mediaserver.");
sp<IOMX> omx = client.interface();
mNativeWindow = new GonkNativeWindow();
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
mNativeWindowClient = new GonkNativeWindowClient(mNativeWindow->getBufferQueue());
#else
mNativeWindowClient = new GonkNativeWindowClient(mNativeWindow);
#endif
// Experience with OMX codecs is that only the HW decoders are
// worth bothering with, at least on the platforms where this code
// is currently used, and for formats this code is currently used
// for (h.264). So if we don't get a hardware decoder, just give
// up.
#ifdef MOZ_OMX_WEBM_DECODER
int flags = 0;//fallback to omx sw decoder if there is no hw decoder
#else
int flags = kHardwareCodecsOnly;
#endif//MOZ_OMX_WEBM_DECODER
if (isInEmulator()) {
// If we are in emulator, allow to fall back to software.
flags = 0;
}
mVideoSource =
OMXCodecProxy::Create(omx,
mVideoTrack->getFormat(),
false, // decoder
mVideoTrack,
nullptr,
flags,
mNativeWindowClient);
if (mVideoSource == nullptr) {
NS_WARNING("Couldn't create OMX video source");
return false;
} else {
sp<OMXCodecProxy::EventListener> listener = this;
mVideoSource->setEventListener(listener);
mVideoSource->requestResource();
}
}
if ((mAudioTrack != nullptr) && (mAudioSource == nullptr)) {
// OMXClient::connect() always returns OK and abort's fatally if
// it can't connect.
OMXClient client;
DebugOnly<status_t> err = client.connect();
NS_ASSERTION(err == OK, "Failed to connect to OMX in mediaserver.");
sp<IOMX> omx = client.interface();
const char *audioMime = nullptr;
sp<MetaData> meta = mAudioTrack->getFormat();
if (!meta->findCString(kKeyMIMEType, &audioMime)) {
return false;
}
if (!strcasecmp(audioMime, "audio/raw")) {
mAudioSource = mAudioTrack;
} else {
// try to load hardware codec in mediaserver process.
int flags = kHardwareCodecsOnly;
mAudioSource = OMXCodec::Create(omx,
mAudioTrack->getFormat(),
false, // decoder
mAudioTrack,
nullptr,
flags);
}
if (mAudioSource == nullptr) {
// try to load software codec in this process.
int flags = kSoftwareCodecsOnly;
mAudioSource = OMXCodec::Create(GetOMX(),
mAudioTrack->getFormat(),
false, // decoder
mAudioTrack,
nullptr,
flags);
if (mAudioSource == nullptr) {
NS_WARNING("Couldn't create OMX audio source");
return false;
}
}
if (mAudioSource->start() != OK) {
NS_WARNING("Couldn't start OMX audio source");
mAudioSource.clear();
return false;
}
}
return true;
}
示例9: NS_ASSERTION
RefPtr<mozilla::MediaOmxCommonReader::MediaResourcePromise>
OmxDecoder::AllocateMediaResources()
{
RefPtr<MediaResourcePromise> p = mMediaResourcePromise.Ensure(__func__);
if ((mVideoTrack != nullptr) && (mVideoSource == nullptr)) {
// OMXClient::connect() always returns OK and abort's fatally if
// it can't connect.
OMXClient client;
DebugOnly<status_t> err = client.connect();
NS_ASSERTION(err == OK, "Failed to connect to OMX in mediaserver.");
sp<IOMX> omx = client.interface();
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 21
sp<IGraphicBufferProducer> producer;
sp<IGonkGraphicBufferConsumer> consumer;
GonkBufferQueue::createBufferQueue(&producer, &consumer);
mNativeWindow = new GonkNativeWindow(consumer);
#else
mNativeWindow = new GonkNativeWindow();
#endif
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 21
mNativeWindowClient = new Surface(producer);
#elif defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
mNativeWindowClient = new Surface(mNativeWindow->getBufferQueue());
#else
mNativeWindowClient = new SurfaceTextureClient(mNativeWindow);
#endif
// Experience with OMX codecs is that only the HW decoders are
// worth bothering with, at least on the platforms where this code
// is currently used, and for formats this code is currently used
// for (h.264). So if we don't get a hardware decoder, just give
// up.
#ifdef MOZ_OMX_WEBM_DECODER
int flags = 0;//fallback to omx sw decoder if there is no hw decoder
#else
int flags = kHardwareCodecsOnly;
#endif//MOZ_OMX_WEBM_DECODER
if (isInEmulator()) {
// If we are in emulator, allow to fall back to software.
flags = 0;
}
mVideoSource =
OMXCodecProxy::Create(omx,
mVideoTrack->getFormat(),
false, // decoder
mVideoTrack,
nullptr,
flags,
mNativeWindowClient);
if (mVideoSource == nullptr) {
NS_WARNING("Couldn't create OMX video source");
mMediaResourcePromise.Reject(true, __func__);
return p;
} else {
sp<OmxDecoder> self = this;
mVideoCodecRequest.Begin(mVideoSource->requestResource()
->Then(OwnerThread(), __func__,
[self] (bool) -> void {
self->mVideoCodecRequest.Complete();
self->mMediaResourcePromise.ResolveIfExists(true, __func__);
}, [self] (bool) -> void {
self->mVideoCodecRequest.Complete();
self->mMediaResourcePromise.RejectIfExists(true, __func__);
}));
}
}
if ((mAudioTrack != nullptr) && (mAudioSource == nullptr)) {
// OMXClient::connect() always returns OK and abort's fatally if
// it can't connect.
OMXClient client;
DebugOnly<status_t> err = client.connect();
NS_ASSERTION(err == OK, "Failed to connect to OMX in mediaserver.");
sp<IOMX> omx = client.interface();
const char *audioMime = nullptr;
sp<MetaData> meta = mAudioTrack->getFormat();
if (!meta->findCString(kKeyMIMEType, &audioMime)) {
mMediaResourcePromise.Reject(true, __func__);
return p;
}
if (!strcasecmp(audioMime, "audio/raw")) {
mAudioSource = mAudioTrack;
} else {
// try to load hardware codec in mediaserver process.
int flags = kHardwareCodecsOnly;
mAudioSource = OMXCodec::Create(omx,
mAudioTrack->getFormat(),
false, // decoder
mAudioTrack,
nullptr,
flags);
}
if (mAudioSource == nullptr) {
// try to load software codec in this process.
//.........这里部分代码省略.........
示例10: main
int main(int argc, char **argv) {
// Default values for the program if not overwritten
int frameRateFps = 30;
int width = 176;
int height = 144;
int bitRateBps = 300000;
int iFramesIntervalSeconds = 1;
int colorFormat = OMX_COLOR_FormatYUV420Planar;
int nFrames = 300;
int level = -1; // Encoder specific default
int profile = -1; // Encoder specific default
int codec = 0;
const char *fileName = "/sdcard/output.mp4";
android::ProcessState::self()->startThreadPool();
int res;
while ((res = getopt(argc, argv, "b:c:f:i:n:w:t:l:p:v:h")) >= 0) {
switch (res) {
case 'b':
{
bitRateBps = atoi(optarg);
break;
}
case 'c':
{
colorFormat = translateColorToOmxEnumValue(atoi(optarg));
if (colorFormat == -1) {
usage(argv[0]);
}
break;
}
case 'f':
{
frameRateFps = atoi(optarg);
break;
}
case 'i':
{
iFramesIntervalSeconds = atoi(optarg);
break;
}
case 'n':
{
nFrames = atoi(optarg);
break;
}
case 'w':
{
width = atoi(optarg);
break;
}
case 't':
{
height = atoi(optarg);
break;
}
case 'l':
{
level = atoi(optarg);
break;
}
case 'p':
{
profile = atoi(optarg);
break;
}
case 'v':
{
codec = atoi(optarg);
if (codec < 0 || codec > 2) {
usage(argv[0]);
}
break;
}
case 'h':
default:
{
usage(argv[0]);
break;
}
}
}
OMXClient client;
CHECK_EQ(client.connect(), OK);
status_t err = OK;
sp<MediaSource> source =
new DummySource(width, height, nFrames, frameRateFps, colorFormat);
//.........这里部分代码省略.........
示例11: ALOGI
status_t MediaCodecList::getCodecCapabilities(
size_t index, const char *type,
Vector<ProfileLevel> *profileLevels,
Vector<uint32_t> *colorFormats,
uint32_t *flags) const {
profileLevels->clear();
colorFormats->clear();
#ifndef ANDROID_DEFAULT_CODE
ALOGI("[%s][ index=%d, mCodecInfos.size()=%d] ",__FUNCTION__,index,mCodecInfos.size() );
#endif
if (index >= mCodecInfos.size()) {
return -ERANGE;
}
const CodecInfo &info = mCodecInfos.itemAt(index);
OMXClient client;
status_t err = client.connect();
if (err != OK) {
#ifndef ANDROID_DEFAULT_CODE
ALOGI("[%s][ err1=%d ] ",__FUNCTION__,err );
#endif
return err;
}
#ifndef ANDROID_DEFAULT_CODE
ALOGI("[%s][ connect OK ] ",__FUNCTION__ );
#endif
CodecCapabilities caps;
err = QueryCodec(
client.interface(),
info.mName.c_str(), type, info.mIsEncoder, &caps);
if (err != OK) {
#ifndef ANDROID_DEFAULT_CODE
ALOGI("[%s][ err2=%d ] ",__FUNCTION__,err );
#endif
return err;
}
#ifndef ANDROID_DEFAULT_CODE
ALOGI("[%s][ QueryCodec OK ] ",__FUNCTION__ );
int memTotalBytes = sysconf(_SC_PHYS_PAGES) * PAGE_SIZE;
ALOGD("native_get_videoeditor_profile: mIsEncoder %d, memTotalBytes %d bytes", info.mIsEncoder, memTotalBytes);
#endif //ANDROID_DEFAULT_CODE
for (size_t i = 0; i < caps.mProfileLevels.size(); ++i) {
const CodecProfileLevel &src = caps.mProfileLevels.itemAt(i);
ProfileLevel profileLevel;
profileLevel.mProfile = src.mProfile;
profileLevel.mLevel = src.mLevel;
#ifndef ANDROID_DEFAULT_CODE
ALOGD("mProfile %d mLevel %d", src.mProfile, src.mLevel);
//for CTS case "EncodeVirtualDisplayWithCompositionTest "
// Limit max recording resolution to 1280x720, if phone's ram <= 512MB
if (memTotalBytes <= (512*1024*1024)) {
if( (1==info.mIsEncoder)&& (OMX_VIDEO_AVCLevel4<=src.mLevel) )
{
ALOGD("skip once, memory may no be enough during large size video recording", src.mProfile, src.mLevel);
continue;
}
}
#endif //ANDROID_DEFAULT_CODE
profileLevels->push(profileLevel);
}
for (size_t i = 0; i < caps.mColorFormats.size(); ++i) {
#ifndef ANDROID_DEFAULT_CODE
//for CTS case "com.android.cts.videoperf.VideoEncoderDecoderTest "
//push one more format(YUV420) if there is under the decoding and with MTKBLK or MTKYV12 format
if( (0==info.mIsEncoder)&&( OMX_COLOR_FormatVendorMTKYUV==caps.mColorFormats.itemAt(i) ||
OMX_MTK_COLOR_FormatYV12==caps.mColorFormats.itemAt(i) || OMX_COLOR_FormatVendorMTKYUV_FCM==caps.mColorFormats.itemAt(i) ) )
{
colorFormats->push(OMX_COLOR_FormatYUV420Planar);
ALOGI("itemAt(i) %x, isEncoder %d ", caps.mColorFormats.itemAt(i), info.mIsEncoder );
}
#endif //ANDROID_DEFAULT_CODE
colorFormats->push(caps.mColorFormats.itemAt(i));
}
*flags = caps.mFlags;
#ifndef ANDROID_DEFAULT_CODE
ALOGI("[%s][ OK ] ",__FUNCTION__ );
#endif
return OK;
}
示例12: AllocateMediaResources
bool OmxDecoder::AllocateMediaResources()
{
// OMXClient::connect() always returns OK and abort's fatally if
// it can't connect.
OMXClient client;
DebugOnly<status_t> err = client.connect();
NS_ASSERTION(err == OK, "Failed to connect to OMX in mediaserver.");
sp<IOMX> omx = client.interface();
if ((mVideoTrack != nullptr) && (mVideoSource == nullptr)) {
mNativeWindow = new GonkNativeWindow();
mNativeWindowClient = new GonkNativeWindowClient(mNativeWindow);
// Experience with OMX codecs is that only the HW decoders are
// worth bothering with, at least on the platforms where this code
// is currently used, and for formats this code is currently used
// for (h.264). So if we don't get a hardware decoder, just give
// up.
int flags = kHardwareCodecsOnly;
char propQemu[PROPERTY_VALUE_MAX];
property_get("ro.kernel.qemu", propQemu, "");
if (!strncmp(propQemu, "1", 1)) {
// If we are in emulator, allow to fall back to software.
flags = 0;
}
mVideoSource =
OMXCodecProxy::Create(omx,
mVideoTrack->getFormat(),
false, // decoder
mVideoTrack,
nullptr,
flags,
mNativeWindowClient);
if (mVideoSource == nullptr) {
NS_WARNING("Couldn't create OMX video source");
return false;
} else {
sp<OMXCodecProxy::EventListener> listener = this;
mVideoSource->setEventListener(listener);
mVideoSource->requestResource();
}
}
if ((mAudioTrack != nullptr) && (mAudioSource == nullptr)) {
const char *audioMime = nullptr;
sp<MetaData> meta = mAudioTrack->getFormat();
if (!meta->findCString(kKeyMIMEType, &audioMime)) {
return false;
}
if (!strcasecmp(audioMime, "audio/raw")) {
mAudioSource = mAudioTrack;
} else {
// try to load hardware codec in mediaserver process.
int flags = kHardwareCodecsOnly;
mAudioSource = OMXCodec::Create(omx,
mAudioTrack->getFormat(),
false, // decoder
mAudioTrack,
nullptr,
flags);
}
if (mAudioSource == nullptr) {
// try to load software codec in this process.
int flags = kSoftwareCodecsOnly;
mAudioSource = OMXCodec::Create(GetOMX(),
mAudioTrack->getFormat(),
false, // decoder
mAudioTrack,
nullptr,
flags);
if (mAudioSource == nullptr) {
NS_WARNING("Couldn't create OMX audio source");
return false;
}
}
if (mAudioSource->start() != OK) {
NS_WARNING("Couldn't start OMX audio source");
return false;
}
}
return true;
}
示例13: strrchr
void MediaCodecList::parseTopLevelXMLFile(const char *codecs_xml) {
// get href_base
char *href_base_end = strrchr(codecs_xml, '/');
if (href_base_end != NULL) {
mHrefBase = AString(codecs_xml, href_base_end - codecs_xml + 1);
}
mInitCheck = OK; // keeping this here for safety
mCurrentSection = SECTION_TOPLEVEL;
mDepth = 0;
OMXClient client;
mInitCheck = client.connect();
if (mInitCheck != OK) {
return;
}
mOMX = client.interface();
parseXMLFile(codecs_xml);
mOMX.clear();
if (mInitCheck != OK) {
mCodecInfos.clear();
return;
}
for (size_t i = mCodecInfos.size(); i-- > 0;) {
const MediaCodecInfo &info = *mCodecInfos.itemAt(i).get();
if (info.mCaps.size() == 0) {
// No types supported by this component???
ALOGW("Component %s does not support any type of media?",
info.mName.c_str());
mCodecInfos.removeAt(i);
#if LOG_NDEBUG == 0
} else {
for (size_t type_ix = 0; type_ix < info.mCaps.size(); ++type_ix) {
AString mime = info.mCaps.keyAt(type_ix);
const sp<MediaCodecInfo::Capabilities> &caps = info.mCaps.valueAt(type_ix);
ALOGV("%s codec info for %s: %s", info.mName.c_str(), mime.c_str(),
caps->getDetails()->debugString().c_str());
ALOGV(" flags=%d", caps->getFlags());
{
Vector<uint32_t> colorFormats;
caps->getSupportedColorFormats(&colorFormats);
AString nice;
for (size_t ix = 0; ix < colorFormats.size(); ix++) {
if (ix > 0) {
nice.append(", ");
}
nice.append(colorFormats.itemAt(ix));
}
ALOGV(" colors=[%s]", nice.c_str());
}
{
Vector<MediaCodecInfo::ProfileLevel> profileLevels;
caps->getSupportedProfileLevels(&profileLevels);
AString nice;
for (size_t ix = 0; ix < profileLevels.size(); ix++) {
if (ix > 0) {
nice.append(", ");
}
const MediaCodecInfo::ProfileLevel &pl =
profileLevels.itemAt(ix);
nice.append(pl.mProfile);
nice.append("/");
nice.append(pl.mLevel);
}
ALOGV(" levels=[%s]", nice.c_str());
}
}
#endif
}
}
// for CTS
#ifdef MTK_AOSP_ENHANCEMENT
#ifndef MTK_WMA_PLAYBACK_SUPPORT
const char* wma_name = "OMX.MTK.AUDIO.DECODER.WMA";
deleteByType(wma_name);
#endif
#ifndef MTK_SWIP_WMAPRO
const char* wmapro_name = "OMX.MTK.AUDIO.DECODER.WMAPRO";
deleteByType(wmapro_name);
#endif
#ifndef MTK_AUDIO_RAW_SUPPORT
const char* pcm_name = "OMX.MTK.AUDIO.DECODER.RAW";
deleteByType(pcm_name);
#endif
#ifndef MTK_AUDIO_DDPLUS_SUPPORT
const char* DDPLUS_name1 = "OMX.dolby.ac3.decoder";
deleteByType(DDPLUS_name1);
const char* DDPLUS_name2 = "OMX.dolby.ec3.decoder";
deleteByType(DDPLUS_name2);
#endif
#ifndef MTK_AUDIO_APE_SUPPORT
const char* ape_name = "OMX.MTK.AUDIO.DECODER.APE";
deleteByType(ape_name);
#endif
#endif
//.........这里部分代码省略.........
示例14: main
int main() {
// We only have an AMR-WB encoder on sholes...
static bool outputWBAMR = false;
static const int32_t kSampleRate = outputWBAMR ? 16000 : 8000;
static const int32_t kNumChannels = 1;
android::ProcessState::self()->startThreadPool();
OMXClient client;
CHECK_EQ(client.connect(), (status_t)OK);
#if 0
sp<MediaSource> source = new SineSource(kSampleRate, kNumChannels);
#else
sp<MediaSource> source = new AudioSource(
AUDIO_SOURCE_DEFAULT,
kSampleRate,
audio_channel_in_mask_from_count(kNumChannels));
#endif
sp<MetaData> meta = new MetaData;
meta->setCString(
kKeyMIMEType,
outputWBAMR ? MEDIA_MIMETYPE_AUDIO_AMR_WB
: MEDIA_MIMETYPE_AUDIO_AMR_NB);
meta->setInt32(kKeyChannelCount, kNumChannels);
meta->setInt32(kKeySampleRate, kSampleRate);
int32_t maxInputSize;
if (source->getFormat()->findInt32(kKeyMaxInputSize, &maxInputSize)) {
meta->setInt32(kKeyMaxInputSize, maxInputSize);
}
sp<MediaSource> encoder = OMXCodec::Create(
client.interface(),
meta, true /* createEncoder */,
source);
#if 1
sp<AMRWriter> writer = new AMRWriter("/sdcard/out.amr");
writer->addSource(encoder);
writer->start();
sleep(10);
writer->stop();
#else
sp<MediaSource> decoder = OMXCodec::Create(
client.interface(),
meta, false /* createEncoder */,
encoder);
#if 0
AudioPlayer *player = new AudioPlayer(NULL);
player->setSource(decoder);
player->start();
sleep(10);
player->stop();
delete player;
player = NULL;
#elif 0
CHECK_EQ(decoder->start(), (status_t)OK);
MediaBuffer *buffer;
while (decoder->read(&buffer) == OK) {
// do something with buffer
putchar('.');
fflush(stdout);
buffer->release();
buffer = NULL;
}
CHECK_EQ(decoder->stop(), (status_t)OK);
#endif
#endif
return 0;
}
示例15: SL_LOGD
//--------------------------------------------------
// Event handlers
void AacBqToPcmCbRenderer::onPrepare() {
SL_LOGD("AacBqToPcmCbRenderer::onPrepare()");
Mutex::Autolock _l(mBufferSourceLock);
// Initialize the PCM format info with the known parameters before the start of the decode
{
android::Mutex::Autolock autoLock(mPcmFormatLock);
mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_BITSPERSAMPLE] = SL_PCMSAMPLEFORMAT_FIXED_16;
mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CONTAINERSIZE] = 16;
//FIXME not true on all platforms
mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_ENDIANNESS] = SL_BYTEORDER_LITTLEENDIAN;
// initialization with the default values: they will be replaced by the actual values
// once the decoder has figured them out
mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS] = UNKNOWN_NUMCHANNELS;
mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_SAMPLERATE] = UNKNOWN_SAMPLERATE;
mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CHANNELMASK] = UNKNOWN_CHANNELMASK;
}
sp<MediaExtractor> extractor = new AacAdtsExtractor(mBqSource);
// only decoding a single track of data
const size_t kTrackToDecode = 0;
sp<MediaSource> source = extractor->getTrack(kTrackToDecode);
if (source == 0) {
SL_LOGE("AacBqToPcmCbRenderer::onPrepare: error getting source from extractor");
notifyPrepared(ERROR_UNSUPPORTED);
return;
}
sp<MetaData> meta = extractor->getTrackMetaData(kTrackToDecode);
// the audio content is not raw PCM, so we need a decoder
OMXClient client;
CHECK_EQ(client.connect(), (status_t)OK);
source = OMXCodec::Create(
client.interface(), meta, false /* createEncoder */,
source);
if (source == NULL) {
SL_LOGE("AacBqToPcmCbRenderer::onPrepare: Could not instantiate decoder.");
notifyPrepared(ERROR_UNSUPPORTED);
return;
}
meta = source->getFormat();
SL_LOGD("AacBqToPcmCbRenderer::onPrepare() after instantiating decoder");
if (source->start() != OK) {
SL_LOGE("AacBqToPcmCbRenderer::onPrepare() Failed to start source/decoder.");
notifyPrepared(MEDIA_ERROR_BASE);
return;
}
//---------------------------------
int32_t channelCount;
CHECK(meta->findInt32(kKeyChannelCount, &channelCount));
int32_t sr;
CHECK(meta->findInt32(kKeySampleRate, &sr));
// FIXME similar to AudioSfDecoder::onPrepare()
// already "good to go" (compare to AudioSfDecoder::onPrepare)
mCacheStatus = kStatusHigh;
mCacheFill = 1000;
notifyStatus();
notifyCacheFill();
{
android::Mutex::Autolock autoLock(mPcmFormatLock);
mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_SAMPLERATE] = sr;
mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS] = channelCount;
mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CHANNELMASK] =
channelCountToMask(channelCount);
}
SL_LOGV("AacBqToPcmCbRenderer::onPrepare() channel count=%d SR=%d",
channelCount, sr);
//---------------------------------
// The data source, and audio source (a decoder) are ready to be used
mDataSource = mBqSource;
mAudioSource = source;
mAudioSourceStarted = true;
//-------------------------------------
// signal successful completion of prepare
mStateFlags |= kFlagPrepared;
// skipping past AudioToCbRenderer and AudioSfDecoder
GenericPlayer::onPrepare();
SL_LOGD("AacBqToPcmCbRenderer::onPrepare() done, mStateFlags=0x%x", mStateFlags);
}