Skip to content

Commit

Permalink
mediacodec: update api
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jun 26, 2017
1 parent cbab79e commit 4204006
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 5 additions & 1 deletion examples/QMLPlayer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ int main(int argc, char *argv[])
options.add(QLatin1String("QMLPlayer options"))
("scale", 1.0, QLatin1String("scale of graphics context. 0: auto"))
;
qputenv("QTAV_MEDIACODEC_KEY", ")A0aZ!WIgo2DdCsc#EnR?NAsFtWrnENONeeiiED^OM@6gI+Hew6s5)77p^>$K(Fe");
options.parse(argc, argv);
Config::setName(QString::fromLatin1("QMLPlayer"));
do_common_options_before_qapp(options);
Expand Down Expand Up @@ -159,9 +160,12 @@ qDebug() << "event dispatcher:" << QCoreApplication::eventDispatcher();
if (player && !file.isEmpty()) {
if (!file.startsWith(QLatin1String("file:")) && QFile(file).exists())
file.prepend(QLatin1String("file:")); //qml use url and will add qrc: if no scheme
#ifdef Q_OS_WIN
file.replace(QLatin1String("\\"), QLatin1String("/")); //qurl
#endif
//QMetaObject::invokeMethod(player, "play", Q_ARG(QUrl, QUrl(file)));
player->setProperty("source", QUrl(file));
QUrl url;
player->setProperty("source", QUrl(file.toUtf8().toPercentEncoding()));
}
#endif
QObject::connect(&Config::instance(), SIGNAL(changed()), &Config::instance(), SLOT(save()));
Expand Down
24 changes: 13 additions & 11 deletions src/codec/video/VideoDecoderMediaCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class VideoDecoderMediaCodecPrivate Q_DECL_FINAL : public VideoDecoderFFmpegHWPr
~VideoDecoderMediaCodecPrivate() {
#ifdef MEDIACODEC_TEXTURE
if (pool_)
mdk_mediacodec_texture_pool_release(&pool_);
api_->texture_pool_release(&pool_);
#endif
}
void close() Q_DECL_OVERRIDE {
Expand All @@ -86,12 +86,12 @@ class VideoDecoderMediaCodecPrivate Q_DECL_FINAL : public VideoDecoderFFmpegHWPr
if (copy_mode != VideoDecoderFFmpegHW::ZeroCopy)
return nullptr;
#ifdef MEDIACODEC_TEXTURE
mdk_mediacodec_set_jvm(QAndroidJniEnvironment::javaVM());
api_->set_jvm(QAndroidJniEnvironment::javaVM());
if (!pool_)
pool_ = mdk_mediacodec_texture_pool_create();
pool_ = api_->texture_pool_create();
av_mediacodec_default_free(avctx);
AVMediaCodecContext *mc = av_mediacodec_alloc_context();
AV_ENSURE(av_mediacodec_default_init(avctx, mc, mdk_mediacodec_texture_pool_ensure_surface(pool_)), nullptr);
AV_ENSURE(av_mediacodec_default_init(avctx, mc, api_->texture_pool_ensure_surface(pool_)), nullptr);
#endif
return avctx->hwaccel_context; // set in av_mediacodec_default_init
}
Expand All @@ -104,7 +104,8 @@ class VideoDecoderMediaCodecPrivate Q_DECL_FINAL : public VideoDecoderFFmpegHWPr
return AV_PIX_FMT_NONE;
}
#ifdef MEDIACODEC_TEXTURE
MdkMediaCodecTexturePool *pool_ = nullptr;
const MdkMediaCodecTextureAPI* api_ = mdk_mediacodec_get_api("qtav.nonfree.mediacodec");
MdkMediaCodecTextureAPI::TexturePool *pool_ = nullptr;
#endif
};

Expand Down Expand Up @@ -163,26 +164,27 @@ VideoFrame VideoDecoderMediaCodec::frame()
#ifdef MEDIACODEC_TEXTURE
class MediaCodecTextureInterop : public VideoSurfaceInterop
{
MdkMediaCodecTexture *tex = nullptr;
const MdkMediaCodecTextureAPI* api_ = nullptr;
MdkMediaCodecTextureAPI::Texture *tex_ = nullptr;
public:
MediaCodecTextureInterop(MdkMediaCodecTexture *mt) : tex(mt) {}
MediaCodecTextureInterop(const MdkMediaCodecTextureAPI *api, MdkMediaCodecTextureAPI::Texture *mt) : api_(api), tex_(mt) {}
~MediaCodecTextureInterop() {
mdk_mediacodec_texture_release(&tex);
api_->texture_release(&tex_);
}

void* map(SurfaceType, const VideoFormat &, void *handle, int plane) {
Q_UNUSED(plane);
GLuint* t = reinterpret_cast<GLuint*>(handle);
*t = mdk_mediacodec_texture_to_gl(tex, nullptr, nullptr);
*t = api_->texture_to_gl(tex_, nullptr, nullptr);
return t;
}
};
assert(d.frame->buf[0] && d.frame->data[3] && "No AVMediaCodecBuffer or ref in AVFrame");
AVBufferRef* bufref = av_buffer_ref(d.frame->buf[0]);
AVMediaCodecBuffer *mcbuf = (AVMediaCodecBuffer*)d.frame->data[3];
MdkMediaCodecTexture* mt = mdk_mediacodec_texture_pool_feed_avbuffer(d.pool_, d.frame->width, d.frame->height, av_mediacodec_buffer_unref, bufref, av_mediacodec_render_buffer, mcbuf);
MdkMediaCodecTextureAPI::Texture* mt = d.api_->texture_pool_feed_avbuffer(d.pool_, d.frame->width, d.frame->height, av_mediacodec_buffer_unref, bufref, av_mediacodec_render_buffer, mcbuf);

MediaCodecTextureInterop *interop = new MediaCodecTextureInterop(mt);
MediaCodecTextureInterop *interop = new MediaCodecTextureInterop(d.api_, mt);
frame.setMetaData(QStringLiteral("surface_interop"), QVariant::fromValue(VideoSurfaceInteropPtr((interop))));
#endif
return frame;
Expand Down

0 comments on commit 4204006

Please sign in to comment.