Commit cbe39fc8 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

video: iOS encoding/decoding

Enable Video Toolbox

Change-Id: I3f20d35c7e66be37954861d2be411a4c16c51257
parent 1aaf0d79
...@@ -201,6 +201,11 @@ endif ...@@ -201,6 +201,11 @@ endif
ifdef HAVE_IOS ifdef HAVE_IOS
FFMPEGCONF += \ FFMPEGCONF += \
--enable-videotoolbox \
--enable-hwaccel=h263_videotoolbox \
--enable-hwaccel=h264_videotoolbox \
--enable-hwaccel=mpeg4_videotoolbox \
--enable-encoder=h264_videotoolbox \
--target-os=darwin \ --target-os=darwin \
--enable-cross-compile \ --enable-cross-compile \
--arch=$(ARCH) \ --arch=$(ARCH) \
......
...@@ -391,6 +391,15 @@ MediaEncoder::encode(VideoFrame& input, bool is_keyframe, int64_t frame_number) ...@@ -391,6 +391,15 @@ MediaEncoder::encode(VideoFrame& input, bool is_keyframe, int64_t frame_number)
#ifdef RING_ACCEL #ifdef RING_ACCEL
auto desc = av_pix_fmt_desc_get(static_cast<AVPixelFormat>(input.format())); auto desc = av_pix_fmt_desc_get(static_cast<AVPixelFormat>(input.format()));
bool isHardware = desc && (desc->flags & AV_PIX_FMT_FLAG_HWACCEL); bool isHardware = desc && (desc->flags & AV_PIX_FMT_FLAG_HWACCEL);
#ifdef ENABLE_VIDEOTOOLBOX
//Videotoolbox handles frames allocations itself and do not need creating frame context manually.
//Now videotoolbox supports only fully accelerated pipeline
bool isVideotoolbox = static_cast<AVPixelFormat>(input.format()) == AV_PIX_FMT_VIDEOTOOLBOX;
if (accel_ && isVideotoolbox) {
// Fully accelerated pipeline, skip main memory
frame = input.pointer();
} else {
#else
std::unique_ptr<VideoFrame> framePtr; std::unique_ptr<VideoFrame> framePtr;
if (accel_ && accel_->isLinked()) { if (accel_ && accel_->isLinked()) {
// Fully accelerated pipeline, skip main memory // Fully accelerated pipeline, skip main memory
...@@ -414,6 +423,7 @@ MediaEncoder::encode(VideoFrame& input, bool is_keyframe, int64_t frame_number) ...@@ -414,6 +423,7 @@ MediaEncoder::encode(VideoFrame& input, bool is_keyframe, int64_t frame_number)
} }
frame = framePtr->pointer(); frame = framePtr->pointer();
} else { } else {
#endif //ENABLE_VIDEOTOOLBOX
#endif #endif
libav_utils::fillWithBlack(scaledFrame_.pointer()); libav_utils::fillWithBlack(scaledFrame_.pointer());
scaler_.scale_with_aspect(input, scaledFrame_); scaler_.scale_with_aspect(input, scaledFrame_);
......
...@@ -148,8 +148,9 @@ HardwareAccel::setDetails(AVCodecContext* codecCtx) ...@@ -148,8 +148,9 @@ HardwareAccel::setDetails(AVCodecContext* codecCtx)
codecCtx->get_format = getFormatCb; codecCtx->get_format = getFormatCb;
codecCtx->thread_safe_callbacks = 1; codecCtx->thread_safe_callbacks = 1;
} else if (type_ == CODEC_ENCODER) { } else if (type_ == CODEC_ENCODER) {
// encoder doesn't need a device context, only a frame context if (framesCtx_)
codecCtx->hw_frames_ctx = av_buffer_ref(framesCtx_); // encoder doesn't need a device context, only a frame context
codecCtx->hw_frames_ctx = av_buffer_ref(framesCtx_);
} }
} }
...@@ -265,9 +266,13 @@ HardwareAccel::setupDecoder(AVCodecID id, int width, int height) ...@@ -265,9 +266,13 @@ HardwareAccel::setupDecoder(AVCodecID id, int width, int height)
for (const auto& api : apiList) { for (const auto& api : apiList) {
if (std::find(api.supportedCodecs.begin(), api.supportedCodecs.end(), id) != api.supportedCodecs.end()) { if (std::find(api.supportedCodecs.begin(), api.supportedCodecs.end(), id) != api.supportedCodecs.end()) {
auto accel = std::make_unique<HardwareAccel>(id, api.name, api.format, api.swFormat, CODEC_DECODER); auto accel = std::make_unique<HardwareAccel>(id, api.name, api.format, api.swFormat, CODEC_DECODER);
if (accel->initDevice() && accel->initFrame(width, height)) { if (accel->initDevice()) {
JAMI_DBG() << "Attempting to use hardware decoder " << accel->getCodecName() << " with " << api.name; // we don't need frame context for videotoolbox
return accel; if (api.format == AV_PIX_FMT_VIDEOTOOLBOX ||
accel->initFrame(width, height)) {
JAMI_DBG() << "Attempting to use hardware dencoder " << accel->getCodecName() << " with " << api.name;
return accel;
}
} }
} }
} }
...@@ -289,11 +294,14 @@ HardwareAccel::setupEncoder(AVCodecID id, int width, int height, AVBufferRef* fr ...@@ -289,11 +294,14 @@ HardwareAccel::setupEncoder(AVCodecID id, int width, int height, AVBufferRef* fr
auto accel = std::make_unique<HardwareAccel>(id, api.name, api.format, api.swFormat, CODEC_ENCODER); auto accel = std::make_unique<HardwareAccel>(id, api.name, api.format, api.swFormat, CODEC_ENCODER);
const auto& codecName = accel->getCodecName(); const auto& codecName = accel->getCodecName();
if (avcodec_find_encoder_by_name(codecName.c_str())) { if (avcodec_find_encoder_by_name(codecName.c_str())) {
// Set up a fully accelerated pipeline, else fallback to using the main memory if (accel->initDevice()) {
if (accel->linkHardware(framesCtx) // we don't need frame context for videotoolbox
|| (accel->initDevice() && accel->initFrame(width, height))) { if (api.format == AV_PIX_FMT_VIDEOTOOLBOX ||
JAMI_DBG() << "Attempting to use hardware encoder " << codecName; accel->linkHardware(framesCtx) ||
return accel; accel->initFrame(width, height)) {
JAMI_DBG() << "Attempting to use hardware encoder " << codecName;
return accel;
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment