提交 66b5ca97 编写于 作者: Z Zhang Rui

android/MediaCodec: mark with pipeline's acode instead of vout's acodec

上级 ef5a31dc
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
typedef struct AMC_Buf_Out { typedef struct AMC_Buf_Out {
int port; int port;
SDL_AMediaCodec *weak_acodec;
SDL_AMediaCodecBufferInfo info; SDL_AMediaCodecBufferInfo info;
double pts; double pts;
} AMC_Buf_Out; } AMC_Buf_Out;
...@@ -218,6 +219,7 @@ static int reconfigure_codec(JNIEnv *env, IJKFF_Pipenode *node) ...@@ -218,6 +219,7 @@ static int reconfigure_codec(JNIEnv *env, IJKFF_Pipenode *node)
static int amc_queue_picture_buffer( static int amc_queue_picture_buffer(
IJKFF_Pipenode *node, IJKFF_Pipenode *node,
int output_buffer_index, int output_buffer_index,
SDL_AMediaCodec *acodec,
SDL_AMediaCodecBufferInfo *buffer_info) SDL_AMediaCodecBufferInfo *buffer_info)
{ {
IJKFF_Pipenode_Opaque *opaque = node->opaque; IJKFF_Pipenode_Opaque *opaque = node->opaque;
...@@ -230,13 +232,19 @@ static int amc_queue_picture_buffer( ...@@ -230,13 +232,19 @@ static int amc_queue_picture_buffer(
int64_t amc_pts = av_rescale_q(buffer_info->presentationTimeUs, AV_TIME_BASE_Q, is->video_st->time_base); int64_t amc_pts = av_rescale_q(buffer_info->presentationTimeUs, AV_TIME_BASE_Q, is->video_st->time_base);
double pts = amc_pts < 0 ? NAN : amc_pts * av_q2d(tb); double pts = amc_pts < 0 ? NAN : amc_pts * av_q2d(tb);
picture.opaque = (void *)(intptr_t)output_buffer_index; memset(&picture, 0, sizeof(AVFrame));
picture.opaque = SDL_VoutAndroid_obtainBufferProxy(opaque->weak_vout, acodec, output_buffer_index);
picture.width = opaque->frame_width; picture.width = opaque->frame_width;
picture.height = opaque->frame_height; picture.height = opaque->frame_height;
picture.format = SDL_FCC__AMC; picture.format = SDL_FCC__AMC;
picture.sample_aspect_ratio = opaque->avctx->sample_aspect_ratio; picture.sample_aspect_ratio = opaque->avctx->sample_aspect_ratio;
return ffp_queue_picture(opaque->ffp, &picture, pts, duration, 0, is->viddec.pkt_serial); int ret = ffp_queue_picture(opaque->ffp, &picture, pts, duration, 0, is->viddec.pkt_serial);
if (ret) {
if (picture.opaque && buffer_info >= 0)
SDL_VoutAndroid_releaseBufferProxyP(opaque->weak_vout, (SDL_AMediaCodecBufferProxy **)&picture.opaque, false);
}
return ret;
} }
static int amc_queue_picture_fake(IJKFF_Pipenode *node, AVPacket *pkt) static int amc_queue_picture_fake(IJKFF_Pipenode *node, AVPacket *pkt)
...@@ -257,7 +265,7 @@ static int amc_queue_picture_fake(IJKFF_Pipenode *node, AVPacket *pkt) ...@@ -257,7 +265,7 @@ static int amc_queue_picture_fake(IJKFF_Pipenode *node, AVPacket *pkt)
memset(&buffer_info, 0, sizeof(buffer_info)); memset(&buffer_info, 0, sizeof(buffer_info));
buffer_info.presentationTimeUs = time_stamp; buffer_info.presentationTimeUs = time_stamp;
return amc_queue_picture_buffer(node, -1, &buffer_info); return amc_queue_picture_buffer(node, -1, NULL, &buffer_info);
} }
static int amc_decode_picture_fake(IJKFF_Pipenode *node, uint32_t timeout_milli) static int amc_decode_picture_fake(IJKFF_Pipenode *node, uint32_t timeout_milli)
...@@ -721,6 +729,7 @@ static int drain_output_buffer_l(JNIEnv *env, IJKFF_Pipenode *node, int64_t time ...@@ -721,6 +729,7 @@ static int drain_output_buffer_l(JNIEnv *env, IJKFF_Pipenode *node, int64_t time
if (opaque->off_buf_out < opaque->n_buf_out) { if (opaque->off_buf_out < opaque->n_buf_out) {
// ALOGD("filling buffer... %d", opaque->off_buf_out); // ALOGD("filling buffer... %d", opaque->off_buf_out);
buf_out = &opaque->amc_buf_out[opaque->off_buf_out++]; buf_out = &opaque->amc_buf_out[opaque->off_buf_out++];
buf_out->weak_acodec = opaque->acodec;
buf_out->port = output_buffer_index; buf_out->port = output_buffer_index;
buf_out->info = bufferInfo; buf_out->info = bufferInfo;
buf_out->pts = pts_from_buffer_info(node, &bufferInfo); buf_out->pts = pts_from_buffer_info(node, &bufferInfo);
...@@ -739,7 +748,7 @@ static int drain_output_buffer_l(JNIEnv *env, IJKFF_Pipenode *node, int64_t time ...@@ -739,7 +748,7 @@ static int drain_output_buffer_l(JNIEnv *env, IJKFF_Pipenode *node, int64_t time
buf_out = &opaque->amc_buf_out[opaque->off_buf_out - 1]; buf_out = &opaque->amc_buf_out[opaque->off_buf_out - 1];
/* new picture is the most aged, send now */ /* new picture is the most aged, send now */
if (pts < buf_out->pts) { if (pts < buf_out->pts) {
ret = amc_queue_picture_buffer(node, output_buffer_index, &bufferInfo); ret = amc_queue_picture_buffer(node, output_buffer_index, opaque->acodec, &bufferInfo);
opaque->last_queued_pts = pts; opaque->last_queued_pts = pts;
// ALOGD("pts = %f", pts); // ALOGD("pts = %f", pts);
} else { } else {
...@@ -749,10 +758,11 @@ static int drain_output_buffer_l(JNIEnv *env, IJKFF_Pipenode *node, int64_t time ...@@ -749,10 +758,11 @@ static int drain_output_buffer_l(JNIEnv *env, IJKFF_Pipenode *node, int64_t time
for (i = opaque->off_buf_out - 1; i >= 0; i--) { for (i = opaque->off_buf_out - 1; i >= 0; i--) {
buf_out = &opaque->amc_buf_out[i]; buf_out = &opaque->amc_buf_out[i];
if (pts > buf_out->pts) { if (pts > buf_out->pts) {
ret = amc_queue_picture_buffer(node, buf_out->port, &buf_out->info); ret = amc_queue_picture_buffer(node, buf_out->port, opaque->acodec, &buf_out->info);
opaque->last_queued_pts = buf_out->pts; opaque->last_queued_pts = buf_out->pts;
// ALOGD("pts = %f", buf_out->pts); // ALOGD("pts = %f", buf_out->pts);
/* replace for sort later */ /* replace for sort later */
buf_out->weak_acodec = opaque->acodec;
buf_out->port = output_buffer_index; buf_out->port = output_buffer_index;
buf_out->info = bufferInfo; buf_out->info = bufferInfo;
buf_out->pts = pts_from_buffer_info(node, &bufferInfo); buf_out->pts = pts_from_buffer_info(node, &bufferInfo);
...@@ -769,7 +779,7 @@ static int drain_output_buffer_l(JNIEnv *env, IJKFF_Pipenode *node, int64_t time ...@@ -769,7 +779,7 @@ static int drain_output_buffer_l(JNIEnv *env, IJKFF_Pipenode *node, int64_t time
} }
} }
} else { } else {
ret = amc_queue_picture_buffer(node, output_buffer_index, &bufferInfo); ret = amc_queue_picture_buffer(node, output_buffer_index, opaque->acodec, &bufferInfo);
} }
} }
......
...@@ -282,7 +282,7 @@ SDL_AMediaCodec *SDL_VoutAndroid_peekAMediaCodec(SDL_Vout *vout) ...@@ -282,7 +282,7 @@ SDL_AMediaCodec *SDL_VoutAndroid_peekAMediaCodec(SDL_Vout *vout)
return acodec; return acodec;
} }
static SDL_AMediaCodecBufferProxy *SDL_VoutAndroid_obtainBufferProxy_l(SDL_Vout *vout, int buffer_index) static SDL_AMediaCodecBufferProxy *SDL_VoutAndroid_obtainBufferProxy_l(SDL_Vout *vout, SDL_AMediaCodec *acodec, int buffer_index)
{ {
SDL_Vout_Opaque *opaque = vout->opaque; SDL_Vout_Opaque *opaque = vout->opaque;
SDL_AMediaCodecBufferProxy *proxy = NULL; SDL_AMediaCodecBufferProxy *proxy = NULL;
...@@ -299,16 +299,16 @@ static SDL_AMediaCodecBufferProxy *SDL_VoutAndroid_obtainBufferProxy_l(SDL_Vout ...@@ -299,16 +299,16 @@ static SDL_AMediaCodecBufferProxy *SDL_VoutAndroid_obtainBufferProxy_l(SDL_Vout
} }
proxy->buffer_id = opaque->next_buffer_id++; proxy->buffer_id = opaque->next_buffer_id++;
proxy->weak_acodec = opaque->acodec; proxy->weak_acodec = acodec;
proxy->buffer_index = buffer_index; proxy->buffer_index = buffer_index;
return proxy; return proxy;
} }
SDL_AMediaCodecBufferProxy *SDL_VoutAndroid_obtainBufferProxy(SDL_Vout *vout, int buffer_index) SDL_AMediaCodecBufferProxy *SDL_VoutAndroid_obtainBufferProxy(SDL_Vout *vout, SDL_AMediaCodec *acodec, int buffer_index)
{ {
SDL_AMediaCodecBufferProxy *proxy = NULL; SDL_AMediaCodecBufferProxy *proxy = NULL;
SDL_LockMutex(vout->mutex); SDL_LockMutex(vout->mutex);
proxy = SDL_VoutAndroid_obtainBufferProxy_l(vout, buffer_index); proxy = SDL_VoutAndroid_obtainBufferProxy_l(vout, acodec, buffer_index);
SDL_UnlockMutex(vout->mutex); SDL_UnlockMutex(vout->mutex);
return proxy; return proxy;
} }
...@@ -335,7 +335,7 @@ static int SDL_VoutAndroid_releaseBufferProxy_l(SDL_Vout *vout, SDL_AMediaCodecB ...@@ -335,7 +335,7 @@ static int SDL_VoutAndroid_releaseBufferProxy_l(SDL_Vout *vout, SDL_AMediaCodecB
sdl_amedia_status_t amc_ret = SDL_AMediaCodec_releaseOutputBuffer(opaque->acodec, proxy->buffer_index, render); sdl_amedia_status_t amc_ret = SDL_AMediaCodec_releaseOutputBuffer(opaque->acodec, proxy->buffer_index, render);
proxy->buffer_index = -1; proxy->buffer_index = -1;
if (amc_ret != SDL_AMEDIA_OK) { if (amc_ret != SDL_AMEDIA_OK) {
ALOGI("%s: [%d] !!!!!!!! AMediaCodec %p: current: %p error: %d\n", __func__, proxy->buffer_id, proxy->weak_acodec, opaque->acodec, (int)amc_ret); ALOGI("%s: [%d] !!!!!!!! AMediaCodec %p: current: %p idx: %d error: %d\n", __func__, proxy->buffer_id, proxy->weak_acodec, opaque->acodec, proxy->buffer_index, (int)amc_ret);
return -1; return -1;
} }
......
...@@ -43,7 +43,7 @@ typedef struct SDL_AMediaCodecBufferProxy SDL_AMediaCodecBufferProxy; ...@@ -43,7 +43,7 @@ typedef struct SDL_AMediaCodecBufferProxy SDL_AMediaCodecBufferProxy;
void SDL_AMediaCodecBufferProxy_lock(SDL_AMediaCodecBufferProxy *proxy); void SDL_AMediaCodecBufferProxy_lock(SDL_AMediaCodecBufferProxy *proxy);
void SDL_AMediaCodecBufferProxy_unlock(SDL_AMediaCodecBufferProxy *proxy); void SDL_AMediaCodecBufferProxy_unlock(SDL_AMediaCodecBufferProxy *proxy);
SDL_AMediaCodecBufferProxy *SDL_VoutAndroid_obtainBufferProxy(SDL_Vout *vout, int buffer_index); SDL_AMediaCodecBufferProxy *SDL_VoutAndroid_obtainBufferProxy(SDL_Vout *vout, SDL_AMediaCodec *acodec, int buffer_index);
int SDL_VoutAndroid_releaseBufferProxyP(SDL_Vout *vout, SDL_AMediaCodecBufferProxy **proxy, bool render); int SDL_VoutAndroid_releaseBufferProxyP(SDL_Vout *vout, SDL_AMediaCodecBufferProxy **proxy, bool render);
int SDL_VoutAndroid_releaseBufferProxyP_l(SDL_Vout *vout, SDL_AMediaCodecBufferProxy **proxy, bool render); int SDL_VoutAndroid_releaseBufferProxyP_l(SDL_Vout *vout, SDL_AMediaCodecBufferProxy **proxy, bool render);
......
...@@ -108,16 +108,16 @@ static int func_fill_frame(SDL_VoutOverlay *overlay, const AVFrame *frame) ...@@ -108,16 +108,16 @@ static int func_fill_frame(SDL_VoutOverlay *overlay, const AVFrame *frame)
assert(frame->format == SDL_FCC__AMC); assert(frame->format == SDL_FCC__AMC);
SDL_VoutOverlay_Opaque *opaque = overlay->opaque; SDL_VoutOverlay_Opaque *opaque = overlay->opaque;
int output_buffer_index = (int)(intptr_t)frame->opaque;
if (!check_object(overlay, __func__)) if (!check_object(overlay, __func__))
return -1; return -1;
if (opaque->buffer_proxy) if (opaque->buffer_proxy)
SDL_VoutAndroid_releaseBufferProxyP(opaque->vout, &opaque->buffer_proxy, false); SDL_VoutAndroid_releaseBufferProxyP(opaque->vout, (SDL_AMediaCodecBufferProxy **)&opaque->buffer_proxy, false);
opaque->acodec = SDL_VoutAndroid_peekAMediaCodec(opaque->vout); opaque->acodec = SDL_VoutAndroid_peekAMediaCodec(opaque->vout);
opaque->buffer_proxy = SDL_VoutAndroid_obtainBufferProxy(opaque->vout, output_buffer_index); // TODO: ref-count buffer_proxy?
opaque->buffer_proxy = (SDL_AMediaCodecBufferProxy *)frame->opaque;
overlay->opaque_class = &g_vout_overlay_amediacodec_class; overlay->opaque_class = &g_vout_overlay_amediacodec_class;
overlay->format = SDL_FCC__AMC; overlay->format = SDL_FCC__AMC;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册