Skip to content
Snippets Groups Projects
Commit cbe39fc8 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk
Browse files

video: iOS encoding/decoding

Enable Video Toolbox

Change-Id: I3f20d35c7e66be37954861d2be411a4c16c51257
parent 1aaf0d79
No related branches found
No related tags found
No related merge requests found
......@@ -201,6 +201,11 @@ endif
ifdef HAVE_IOS
FFMPEGCONF += \
--enable-videotoolbox \
--enable-hwaccel=h263_videotoolbox \
--enable-hwaccel=h264_videotoolbox \
--enable-hwaccel=mpeg4_videotoolbox \
--enable-encoder=h264_videotoolbox \
--target-os=darwin \
--enable-cross-compile \
--arch=$(ARCH) \
......
......@@ -391,6 +391,15 @@ MediaEncoder::encode(VideoFrame& input, bool is_keyframe, int64_t frame_number)
#ifdef RING_ACCEL
auto desc = av_pix_fmt_desc_get(static_cast<AVPixelFormat>(input.format()));
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;
if (accel_ && accel_->isLinked()) {
// Fully accelerated pipeline, skip main memory
......@@ -414,6 +423,7 @@ MediaEncoder::encode(VideoFrame& input, bool is_keyframe, int64_t frame_number)
}
frame = framePtr->pointer();
} else {
#endif //ENABLE_VIDEOTOOLBOX
#endif
libav_utils::fillWithBlack(scaledFrame_.pointer());
scaler_.scale_with_aspect(input, scaledFrame_);
......
......@@ -148,6 +148,7 @@ HardwareAccel::setDetails(AVCodecContext* codecCtx)
codecCtx->get_format = getFormatCb;
codecCtx->thread_safe_callbacks = 1;
} else if (type_ == CODEC_ENCODER) {
if (framesCtx_)
// encoder doesn't need a device context, only a frame context
codecCtx->hw_frames_ctx = av_buffer_ref(framesCtx_);
}
......@@ -265,12 +266,16 @@ HardwareAccel::setupDecoder(AVCodecID id, int width, int height)
for (const auto& api : apiList) {
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);
if (accel->initDevice() && accel->initFrame(width, height)) {
JAMI_DBG() << "Attempting to use hardware decoder " << accel->getCodecName() << " with " << api.name;
if (accel->initDevice()) {
// we don't need frame context for videotoolbox
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;
}
}
}
}
return nullptr;
}
......@@ -289,15 +294,18 @@ 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);
const auto& codecName = accel->getCodecName();
if (avcodec_find_encoder_by_name(codecName.c_str())) {
// Set up a fully accelerated pipeline, else fallback to using the main memory
if (accel->linkHardware(framesCtx)
|| (accel->initDevice() && accel->initFrame(width, height))) {
if (accel->initDevice()) {
// we don't need frame context for videotoolbox
if (api.format == AV_PIX_FMT_VIDEOTOOLBOX ||
accel->linkHardware(framesCtx) ||
accel->initFrame(width, height)) {
JAMI_DBG() << "Attempting to use hardware encoder " << codecName;
return accel;
}
}
}
}
}
JAMI_WARN() << "Not using hardware encoding";
return nullptr;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment