Skip to content

Commit

Permalink
fix(MediaCodec): get right width and height
Browse files Browse the repository at this point in the history
  • Loading branch information
I-m-SuperMan committed Feb 7, 2020
1 parent cce5cd0 commit ca1dd84
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
19 changes: 14 additions & 5 deletions framework/codec/Android/mediaCodecDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ namespace Cicada {

if (pPacket != nullptr) {
AF_LOGI("send Frame mFlushState = 2. pts %"
PRId64, pPacket->getInfo().pts);
PRId64, pPacket->getInfo().pts);
}

mFlushState = 2;
Expand Down Expand Up @@ -224,9 +224,18 @@ namespace Cicada {
mc_out out{};
mDecoder->get_out(index, &out, false);
mVideoInfo.height = out.conf.video.height;

if (out.conf.video.crop_bottom != MC_ERROR && out.conf.video.crop_top != MC_ERROR) {
mVideoInfo.height = out.conf.video.crop_bottom + 1 - out.conf.video.crop_top;
}

mVideoInfo.width = out.conf.video.width;

if (out.conf.video.crop_right != MC_ERROR && out.conf.video.crop_left != MC_ERROR) {
mVideoInfo.width = out.conf.video.crop_right + 1 - out.conf.video.crop_left;
}

return -EAGAIN;
// TODO: crop info
} else if (index >= 0) {
mc_out out{};
ret = mDecoder->get_out(index, &out, false);
Expand All @@ -239,9 +248,9 @@ namespace Cicada {
}

pFrame = unique_ptr<AFMediaCodecFrame>(new AFMediaCodecFrame(IAFFrame::FrameTypeVideo, index,
[this](int index, bool render) {
mDecoder->release_out(index, render);
}));
[this](int index, bool render) {
mDecoder->release_out(index, render);
}));
// AF_LOGD("mediacodec out pts %" PRId64, out.buf.pts);
pFrame->getInfo().video = mVideoInfo;
pFrame->getInfo().pts = out.buf.pts != -1 ? out.buf.pts : INT64_MIN;
Expand Down
30 changes: 15 additions & 15 deletions framework/codec/Android/mediacodec_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ namespace Cicada {
/* getInteger can throw nullptrPointerException (when fetching the
* "channel-mask" property for example) */
if (JniException::clearException(env)) {
return 0;
return MC_ERROR;
}

return i_ret;
} else {
return 0;
return MC_ERROR;
}
}

Expand Down Expand Up @@ -251,7 +251,7 @@ namespace Cicada {
size_t h264_profile, bool *p_adaptive)
{
JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();

if (!handle) {
AF_LOGE("jni attach failed.");
Expand Down Expand Up @@ -418,7 +418,7 @@ namespace Cicada {
int MediaCodec_JNI::init(const char *mime, int category, jobject surface)
{
JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();

if (!handle) {
AF_LOGE("env is nullptr.");
Expand All @@ -443,7 +443,7 @@ namespace Cicada {
AndroidJniHandle<jobject> joutput_buffers;
jobject jbuffer_info;
JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();

if (!handle) {
AF_LOGE("env is nullptr.");
Expand Down Expand Up @@ -497,7 +497,7 @@ namespace Cicada {
int MediaCodec_JNI::stop()
{
JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();

if (!handle) {
AF_LOGE("env is nullptr.");
Expand Down Expand Up @@ -537,7 +537,7 @@ namespace Cicada {
int MediaCodec_JNI::flush()
{
JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();

if (!handle) {
AF_LOGE("env is nullptr.");
Expand All @@ -557,7 +557,7 @@ namespace Cicada {
int MediaCodec_JNI::dequeue_in(int64_t timeout)
{
JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();

if (!handle) {
AF_LOGE("env is nullptr.");
Expand Down Expand Up @@ -587,7 +587,7 @@ namespace Cicada {
}

JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();

if (!handle) {
AF_LOGE("env is nullptr.");
Expand Down Expand Up @@ -648,7 +648,7 @@ namespace Cicada {
int MediaCodec_JNI::dequeue_out(int64_t timeout)
{
JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();

if (!handle) {
AF_LOGE("env is nullptr.");
Expand Down Expand Up @@ -678,7 +678,7 @@ namespace Cicada {
int MediaCodec_JNI::get_out(int index, mc_out *out, bool readBuffer)
{
JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();

if (!handle) {
AF_LOGE("env is nullptr.");
Expand Down Expand Up @@ -794,7 +794,7 @@ namespace Cicada {
{
bool b_adaptive;
JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();
std::string psz_name = mediaCodecGetName(psz_mime, args, i_h264_profile, &b_adaptive);
AF_LOGI("android decode name %s, b_adaptive %d", psz_name.c_str(), b_adaptive);

Expand Down Expand Up @@ -868,7 +868,7 @@ namespace Cicada {
void MediaCodec_JNI::unInit()
{
JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();

if (!handle) {
AF_LOGE("env is nullptr.");
Expand All @@ -890,7 +890,7 @@ namespace Cicada {
int MediaCodec_JNI::setOutputSurface(jobject surface)
{
JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();

if (!handle) {
AF_LOGE("env is nullptr.");
Expand All @@ -914,7 +914,7 @@ namespace Cicada {
}

JniEnv jniEnv;
JNIEnv* handle = jniEnv.getEnv();
JNIEnv *handle = jniEnv.getEnv();

if (!handle) {
AF_LOGE("env is nullptr.");
Expand Down

0 comments on commit ca1dd84

Please sign in to comment.