2015-06-29 14:34:58 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
Reland of Split iOS sdk in to separate targets (patchset #1 id:1 of https://codereview.webrtc.org/2911053002/ )
Reason for revert:
Take three of relanding this after all internal issues have been resolved.
Original issue's description:
> Revert of Split iOS sdk in to separate targets (patchset #3 id:320001 of https://codereview.webrtc.org/2893843003/ )
>
> Reason for revert:
> Breaks downstream project.
>
> Original issue's description:
> > Reland of Split iOS sdk in to separate targets (patchset #1 id:1 of https://codereview.webrtc.org/2893593002/ )
> >
> > Reason for revert:
> > Take two of fixing downstream issues?
> >
> > Original issue's description:
> > > Revert of Split iOS sdk in to separate targets (patchset #1 id:1 of https://codereview.webrtc.org/2890733003/ )
> > >
> > > Reason for revert:
> > > Still problems with downstream projects
> > >
> > > Original issue's description:
> > > > Reland of Split iOS sdk in to separate targets (patchset #1 id:1 of https://codereview.webrtc.org/2890513002/ )
> > > >
> > > > Reason for revert:
> > > > Fixing downstream breakages
> > > >
> > > > Original issue's description:
> > > > > Revert of Split iOS sdk in to separate targets (patchset #13 id:280001 of https://codereview.webrtc.org/2862543002/ )
> > > > >
> > > > > Reason for revert:
> > > > > Breaking downstream projects.
> > > > >
> > > > > Original issue's description:
> > > > > > Split iOS sdk in to separate targets
> > > > > >
> > > > > > This CL splits the iOS sdk into separate static libraries for video,
> > > > > > audio, ui, common, and peerconnection-related code. This will in the
> > > > > > future make it easier to compile WebRTC without unneeded components.
> > > > > >
> > > > > > BUG=webrtc:4867
> > > > > >
> > > > > > Review-Url: https://codereview.webrtc.org/2862543002
> > > > > > Cr-Commit-Position: refs/heads/master@{#18166}
> > > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/52c83fe7102f566cf35a7533092873d58b38f426
> > > > >
> > > > > TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,kthelgason@webrtc.org
> > > > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > > > NOPRESUBMIT=true
> > > > > NOTREECHECKS=true
> > > > > NOTRY=true
> > > > > BUG=webrtc:4867
> > > > >
> > > > > Review-Url: https://codereview.webrtc.org/2890513002
> > > > > Cr-Commit-Position: refs/heads/master@{#18170}
> > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/9756238084707787f735e1294e896e462e459717
> > > >
> > > > TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org
> > > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > > NOPRESUBMIT=true
> > > > NOTREECHECKS=true
> > > > NOTRY=true
> > > > BUG=webrtc:4867
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2890733003
> > > > Cr-Commit-Position: refs/heads/master@{#18174}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/d51e042492bedd057bc0cac7828979d5c7369cea
> > >
> > > TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:4867
> > >
> > > Review-Url: https://codereview.webrtc.org/2893593002
> > > Cr-Commit-Position: refs/heads/master@{#18182}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/37144b214e2baf62ecb262ab878dde8c59cdd6a3
> >
> > TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org
> > # Skipping CQ checks because original CL landed less than 1 days ago.
> > NOPRESUBMIT=true
> > NOTREECHECKS=true
> > NOTRY=true
> > BUG=webrtc:4867
> >
> > Review-Url: https://codereview.webrtc.org/2893843003
> > Cr-Commit-Position: refs/heads/master@{#18303}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/580c3522d294c877adfe555048c675bd8d166657
>
> TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org,kthelgason@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:4867
>
> Review-Url: https://codereview.webrtc.org/2911053002
> Cr-Commit-Position: refs/heads/master@{#18309}
> Committed: https://chromium.googlesource.com/external/webrtc/+/af5c05540cc8208f682cafe88c5c16a505479196
TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org,mbonadei@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:4867
Review-Url: https://codereview.webrtc.org/2913753003
Cr-Commit-Position: refs/heads/master@{#18319}
2017-05-30 01:48:47 -07:00
|
|
|
#include "webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.h"
|
2015-06-29 14:34:58 -07:00
|
|
|
|
2016-02-29 05:51:59 -08:00
|
|
|
#include <memory>
|
|
|
|
|
|
2015-06-29 14:34:58 -07:00
|
|
|
#include "libyuv/convert.h"
|
2017-01-10 07:44:26 -08:00
|
|
|
#include "webrtc/api/video/video_frame.h"
|
2017-05-15 02:42:11 -07:00
|
|
|
#include "webrtc/common_video/include/video_frame.h"
|
2017-07-07 03:09:51 -07:00
|
|
|
#include "webrtc/rtc_base/checks.h"
|
|
|
|
|
#include "webrtc/rtc_base/logging.h"
|
2017-06-22 15:26:30 +02:00
|
|
|
#include "webrtc/sdk/objc/Framework/Classes/Video/objc_frame_buffer.h"
|
Reland of Split iOS sdk in to separate targets (patchset #1 id:1 of https://codereview.webrtc.org/2911053002/ )
Reason for revert:
Take three of relanding this after all internal issues have been resolved.
Original issue's description:
> Revert of Split iOS sdk in to separate targets (patchset #3 id:320001 of https://codereview.webrtc.org/2893843003/ )
>
> Reason for revert:
> Breaks downstream project.
>
> Original issue's description:
> > Reland of Split iOS sdk in to separate targets (patchset #1 id:1 of https://codereview.webrtc.org/2893593002/ )
> >
> > Reason for revert:
> > Take two of fixing downstream issues?
> >
> > Original issue's description:
> > > Revert of Split iOS sdk in to separate targets (patchset #1 id:1 of https://codereview.webrtc.org/2890733003/ )
> > >
> > > Reason for revert:
> > > Still problems with downstream projects
> > >
> > > Original issue's description:
> > > > Reland of Split iOS sdk in to separate targets (patchset #1 id:1 of https://codereview.webrtc.org/2890513002/ )
> > > >
> > > > Reason for revert:
> > > > Fixing downstream breakages
> > > >
> > > > Original issue's description:
> > > > > Revert of Split iOS sdk in to separate targets (patchset #13 id:280001 of https://codereview.webrtc.org/2862543002/ )
> > > > >
> > > > > Reason for revert:
> > > > > Breaking downstream projects.
> > > > >
> > > > > Original issue's description:
> > > > > > Split iOS sdk in to separate targets
> > > > > >
> > > > > > This CL splits the iOS sdk into separate static libraries for video,
> > > > > > audio, ui, common, and peerconnection-related code. This will in the
> > > > > > future make it easier to compile WebRTC without unneeded components.
> > > > > >
> > > > > > BUG=webrtc:4867
> > > > > >
> > > > > > Review-Url: https://codereview.webrtc.org/2862543002
> > > > > > Cr-Commit-Position: refs/heads/master@{#18166}
> > > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/52c83fe7102f566cf35a7533092873d58b38f426
> > > > >
> > > > > TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,kthelgason@webrtc.org
> > > > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > > > NOPRESUBMIT=true
> > > > > NOTREECHECKS=true
> > > > > NOTRY=true
> > > > > BUG=webrtc:4867
> > > > >
> > > > > Review-Url: https://codereview.webrtc.org/2890513002
> > > > > Cr-Commit-Position: refs/heads/master@{#18170}
> > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/9756238084707787f735e1294e896e462e459717
> > > >
> > > > TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org
> > > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > > NOPRESUBMIT=true
> > > > NOTREECHECKS=true
> > > > NOTRY=true
> > > > BUG=webrtc:4867
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2890733003
> > > > Cr-Commit-Position: refs/heads/master@{#18174}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/d51e042492bedd057bc0cac7828979d5c7369cea
> > >
> > > TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:4867
> > >
> > > Review-Url: https://codereview.webrtc.org/2893593002
> > > Cr-Commit-Position: refs/heads/master@{#18182}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/37144b214e2baf62ecb262ab878dde8c59cdd6a3
> >
> > TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org
> > # Skipping CQ checks because original CL landed less than 1 days ago.
> > NOPRESUBMIT=true
> > NOTREECHECKS=true
> > NOTRY=true
> > BUG=webrtc:4867
> >
> > Review-Url: https://codereview.webrtc.org/2893843003
> > Cr-Commit-Position: refs/heads/master@{#18303}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/580c3522d294c877adfe555048c675bd8d166657
>
> TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org,kthelgason@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:4867
>
> Review-Url: https://codereview.webrtc.org/2911053002
> Cr-Commit-Position: refs/heads/master@{#18309}
> Committed: https://chromium.googlesource.com/external/webrtc/+/af5c05540cc8208f682cafe88c5c16a505479196
TBR=magjed@webrtc.org,denicija@webrtc.org,tkchin@webrtc.org,henrika@webrtc.org,charujain@webrtc.org,mbonadei@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:4867
Review-Url: https://codereview.webrtc.org/2913753003
Cr-Commit-Position: refs/heads/master@{#18319}
2017-05-30 01:48:47 -07:00
|
|
|
#include "webrtc/sdk/objc/Framework/Classes/VideoToolbox/nalu_rewriter.h"
|
2015-06-29 14:34:58 -07:00
|
|
|
|
2017-06-22 15:26:30 +02:00
|
|
|
#import "WebRTC/RTCVideoFrameBuffer.h"
|
|
|
|
|
|
2017-06-12 14:16:20 +02:00
|
|
|
#if defined(WEBRTC_IOS)
|
|
|
|
|
#import "Common/RTCUIApplicationStatusObserver.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-04-13 06:51:26 -07:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace {
|
2015-06-29 14:34:58 -07:00
|
|
|
|
2016-04-04 14:10:43 -07:00
|
|
|
static const int64_t kMsPerSec = 1000;
|
|
|
|
|
|
2015-06-29 14:34:58 -07:00
|
|
|
// Convenience function for creating a dictionary.
|
|
|
|
|
inline CFDictionaryRef CreateCFDictionary(CFTypeRef* keys,
|
|
|
|
|
CFTypeRef* values,
|
|
|
|
|
size_t size) {
|
|
|
|
|
return CFDictionaryCreate(nullptr, keys, values, size,
|
|
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Struct that we pass to the decoder per frame to decode. We receive it again
|
|
|
|
|
// in the decoder callback.
|
|
|
|
|
struct FrameDecodeParams {
|
2017-04-13 06:51:26 -07:00
|
|
|
FrameDecodeParams(DecodedImageCallback* cb, int64_t ts)
|
2015-06-29 14:34:58 -07:00
|
|
|
: callback(cb), timestamp(ts) {}
|
2017-04-13 06:51:26 -07:00
|
|
|
DecodedImageCallback* callback;
|
2015-06-29 14:34:58 -07:00
|
|
|
int64_t timestamp;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// This is the callback function that VideoToolbox calls when decode is
|
|
|
|
|
// complete.
|
|
|
|
|
void VTDecompressionOutputCallback(void* decoder,
|
|
|
|
|
void* params,
|
|
|
|
|
OSStatus status,
|
|
|
|
|
VTDecodeInfoFlags info_flags,
|
|
|
|
|
CVImageBufferRef image_buffer,
|
|
|
|
|
CMTime timestamp,
|
|
|
|
|
CMTime duration) {
|
2016-02-29 05:51:59 -08:00
|
|
|
std::unique_ptr<FrameDecodeParams> decode_params(
|
2015-06-29 14:34:58 -07:00
|
|
|
reinterpret_cast<FrameDecodeParams*>(params));
|
|
|
|
|
if (status != noErr) {
|
|
|
|
|
LOG(LS_ERROR) << "Failed to decode frame. Status: " << status;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// TODO(tkchin): Handle CVO properly.
|
2017-06-22 15:26:30 +02:00
|
|
|
rtc::scoped_refptr<VideoFrameBuffer> buffer = new rtc::RefCountedObject<ObjCFrameBuffer>(
|
|
|
|
|
[[RTCCVPixelBuffer alloc] initWithPixelBuffer:image_buffer]);
|
2017-04-13 06:51:26 -07:00
|
|
|
VideoFrame decoded_frame(buffer, decode_params->timestamp,
|
|
|
|
|
CMTimeGetSeconds(timestamp) * kMsPerSec,
|
|
|
|
|
kVideoRotation_0);
|
2015-06-29 14:34:58 -07:00
|
|
|
decode_params->callback->Decoded(decoded_frame);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-13 06:51:26 -07:00
|
|
|
} // namespace
|
2015-06-29 14:34:58 -07:00
|
|
|
|
|
|
|
|
H264VideoToolboxDecoder::H264VideoToolboxDecoder()
|
2017-06-12 14:16:20 +02:00
|
|
|
: callback_(nullptr), video_format_(nullptr), decompression_session_(nullptr) {}
|
2015-06-29 14:34:58 -07:00
|
|
|
|
|
|
|
|
H264VideoToolboxDecoder::~H264VideoToolboxDecoder() {
|
|
|
|
|
DestroyDecompressionSession();
|
|
|
|
|
SetVideoFormat(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int H264VideoToolboxDecoder::InitDecode(const VideoCodec* video_codec,
|
|
|
|
|
int number_of_cores) {
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int H264VideoToolboxDecoder::Decode(
|
|
|
|
|
const EncodedImage& input_image,
|
|
|
|
|
bool missing_frames,
|
|
|
|
|
const RTPFragmentationHeader* fragmentation,
|
|
|
|
|
const CodecSpecificInfo* codec_specific_info,
|
|
|
|
|
int64_t render_time_ms) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(input_image._buffer);
|
2015-06-29 14:34:58 -07:00
|
|
|
|
2016-03-08 10:51:54 -08:00
|
|
|
#if defined(WEBRTC_IOS)
|
2017-06-12 14:16:20 +02:00
|
|
|
if (![[RTCUIApplicationStatusObserver sharedInstance] isApplicationActive]) {
|
2016-03-08 10:51:54 -08:00
|
|
|
// Ignore all decode requests when app isn't active. In this state, the
|
|
|
|
|
// hardware decoder has been invalidated by the OS.
|
|
|
|
|
// Reset video format so that we won't process frames until the next
|
|
|
|
|
// keyframe.
|
|
|
|
|
SetVideoFormat(nullptr);
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_NO_OUTPUT;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
CMVideoFormatDescriptionRef input_format = nullptr;
|
|
|
|
|
if (H264AnnexBBufferHasVideoFormatDescription(input_image._buffer,
|
|
|
|
|
input_image._length)) {
|
|
|
|
|
input_format = CreateVideoFormatDescription(input_image._buffer,
|
|
|
|
|
input_image._length);
|
|
|
|
|
if (input_format) {
|
|
|
|
|
// Check if the video format has changed, and reinitialize decoder if
|
|
|
|
|
// needed.
|
|
|
|
|
if (!CMFormatDescriptionEqual(input_format, video_format_)) {
|
|
|
|
|
SetVideoFormat(input_format);
|
|
|
|
|
ResetDecompressionSession();
|
|
|
|
|
}
|
|
|
|
|
CFRelease(input_format);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!video_format_) {
|
|
|
|
|
// We received a frame but we don't have format information so we can't
|
|
|
|
|
// decode it.
|
|
|
|
|
// This can happen after backgrounding. We need to wait for the next
|
|
|
|
|
// sps/pps before we can resume so we request a keyframe by returning an
|
|
|
|
|
// error.
|
|
|
|
|
LOG(LS_WARNING) << "Missing video format. Frame with sps/pps required.";
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
2015-06-29 14:34:58 -07:00
|
|
|
CMSampleBufferRef sample_buffer = nullptr;
|
|
|
|
|
if (!H264AnnexBBufferToCMSampleBuffer(input_image._buffer,
|
2015-12-21 03:04:49 -08:00
|
|
|
input_image._length, video_format_,
|
2015-06-29 14:34:58 -07:00
|
|
|
&sample_buffer)) {
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(sample_buffer);
|
2015-06-29 14:34:58 -07:00
|
|
|
VTDecodeFrameFlags decode_flags =
|
|
|
|
|
kVTDecodeFrame_EnableAsynchronousDecompression;
|
2017-04-13 06:51:26 -07:00
|
|
|
std::unique_ptr<FrameDecodeParams> frame_decode_params;
|
2015-06-29 14:34:58 -07:00
|
|
|
frame_decode_params.reset(
|
2017-04-13 06:51:26 -07:00
|
|
|
new FrameDecodeParams(callback_, input_image._timeStamp));
|
2015-06-29 14:34:58 -07:00
|
|
|
OSStatus status = VTDecompressionSessionDecodeFrame(
|
|
|
|
|
decompression_session_, sample_buffer, decode_flags,
|
|
|
|
|
frame_decode_params.release(), nullptr);
|
2016-03-08 10:51:54 -08:00
|
|
|
#if defined(WEBRTC_IOS)
|
|
|
|
|
// Re-initialize the decoder if we have an invalid session while the app is
|
|
|
|
|
// active and retry the decode request.
|
|
|
|
|
if (status == kVTInvalidSessionErr &&
|
|
|
|
|
ResetDecompressionSession() == WEBRTC_VIDEO_CODEC_OK) {
|
|
|
|
|
frame_decode_params.reset(
|
2017-04-13 06:51:26 -07:00
|
|
|
new FrameDecodeParams(callback_, input_image._timeStamp));
|
2016-03-08 10:51:54 -08:00
|
|
|
status = VTDecompressionSessionDecodeFrame(
|
|
|
|
|
decompression_session_, sample_buffer, decode_flags,
|
|
|
|
|
frame_decode_params.release(), nullptr);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2015-06-29 14:34:58 -07:00
|
|
|
CFRelease(sample_buffer);
|
|
|
|
|
if (status != noErr) {
|
|
|
|
|
LOG(LS_ERROR) << "Failed to decode frame with code: " << status;
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int H264VideoToolboxDecoder::RegisterDecodeCompleteCallback(
|
|
|
|
|
DecodedImageCallback* callback) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(!callback_);
|
2015-06-29 14:34:58 -07:00
|
|
|
callback_ = callback;
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int H264VideoToolboxDecoder::Release() {
|
2016-02-23 22:49:42 -08:00
|
|
|
// Need to invalidate the session so that callbacks no longer occur and it
|
|
|
|
|
// is safe to null out the callback.
|
|
|
|
|
DestroyDecompressionSession();
|
|
|
|
|
SetVideoFormat(nullptr);
|
2015-06-29 14:34:58 -07:00
|
|
|
callback_ = nullptr;
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int H264VideoToolboxDecoder::ResetDecompressionSession() {
|
|
|
|
|
DestroyDecompressionSession();
|
|
|
|
|
|
|
|
|
|
// Need to wait for the first SPS to initialize decoder.
|
|
|
|
|
if (!video_format_) {
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set keys for OpenGL and IOSurface compatibilty, which makes the encoder
|
|
|
|
|
// create pixel buffers with GPU backed memory. The intent here is to pass
|
|
|
|
|
// the pixel buffers directly so we avoid a texture upload later during
|
|
|
|
|
// rendering. This currently is moot because we are converting back to an
|
|
|
|
|
// I420 frame after decode, but eventually we will be able to plumb
|
|
|
|
|
// CVPixelBuffers directly to the renderer.
|
|
|
|
|
// TODO(tkchin): Maybe only set OpenGL/IOSurface keys if we know that that
|
|
|
|
|
// we can pass CVPixelBuffers as native handles in decoder output.
|
|
|
|
|
static size_t const attributes_size = 3;
|
|
|
|
|
CFTypeRef keys[attributes_size] = {
|
|
|
|
|
#if defined(WEBRTC_IOS)
|
|
|
|
|
kCVPixelBufferOpenGLESCompatibilityKey,
|
|
|
|
|
#elif defined(WEBRTC_MAC)
|
|
|
|
|
kCVPixelBufferOpenGLCompatibilityKey,
|
|
|
|
|
#endif
|
|
|
|
|
kCVPixelBufferIOSurfacePropertiesKey,
|
|
|
|
|
kCVPixelBufferPixelFormatTypeKey
|
|
|
|
|
};
|
2017-04-13 06:51:26 -07:00
|
|
|
CFDictionaryRef io_surface_value = CreateCFDictionary(nullptr, nullptr, 0);
|
2015-06-29 14:34:58 -07:00
|
|
|
int64_t nv12type = kCVPixelFormatType_420YpCbCr8BiPlanarFullRange;
|
|
|
|
|
CFNumberRef pixel_format =
|
|
|
|
|
CFNumberCreate(nullptr, kCFNumberLongType, &nv12type);
|
2015-12-21 03:04:49 -08:00
|
|
|
CFTypeRef values[attributes_size] = {kCFBooleanTrue, io_surface_value,
|
|
|
|
|
pixel_format};
|
2015-06-29 14:34:58 -07:00
|
|
|
CFDictionaryRef attributes =
|
2017-04-13 06:51:26 -07:00
|
|
|
CreateCFDictionary(keys, values, attributes_size);
|
2015-06-29 14:34:58 -07:00
|
|
|
if (io_surface_value) {
|
|
|
|
|
CFRelease(io_surface_value);
|
|
|
|
|
io_surface_value = nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (pixel_format) {
|
|
|
|
|
CFRelease(pixel_format);
|
|
|
|
|
pixel_format = nullptr;
|
|
|
|
|
}
|
|
|
|
|
VTDecompressionOutputCallbackRecord record = {
|
2017-04-13 06:51:26 -07:00
|
|
|
VTDecompressionOutputCallback, this,
|
2015-06-29 14:34:58 -07:00
|
|
|
};
|
|
|
|
|
OSStatus status =
|
|
|
|
|
VTDecompressionSessionCreate(nullptr, video_format_, nullptr, attributes,
|
|
|
|
|
&record, &decompression_session_);
|
|
|
|
|
CFRelease(attributes);
|
|
|
|
|
if (status != noErr) {
|
|
|
|
|
DestroyDecompressionSession();
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
|
|
|
|
ConfigureDecompressionSession();
|
|
|
|
|
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void H264VideoToolboxDecoder::ConfigureDecompressionSession() {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(decompression_session_);
|
2015-06-29 14:34:58 -07:00
|
|
|
#if defined(WEBRTC_IOS)
|
|
|
|
|
VTSessionSetProperty(decompression_session_,
|
|
|
|
|
kVTDecompressionPropertyKey_RealTime, kCFBooleanTrue);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void H264VideoToolboxDecoder::DestroyDecompressionSession() {
|
|
|
|
|
if (decompression_session_) {
|
|
|
|
|
VTDecompressionSessionInvalidate(decompression_session_);
|
2016-03-08 10:51:54 -08:00
|
|
|
CFRelease(decompression_session_);
|
2015-06-29 14:34:58 -07:00
|
|
|
decompression_session_ = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void H264VideoToolboxDecoder::SetVideoFormat(
|
|
|
|
|
CMVideoFormatDescriptionRef video_format) {
|
|
|
|
|
if (video_format_ == video_format) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (video_format_) {
|
|
|
|
|
CFRelease(video_format_);
|
|
|
|
|
}
|
|
|
|
|
video_format_ = video_format;
|
|
|
|
|
if (video_format_) {
|
|
|
|
|
CFRetain(video_format_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-18 16:01:11 +01:00
|
|
|
const char* H264VideoToolboxDecoder::ImplementationName() const {
|
|
|
|
|
return "VideoToolbox";
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-29 14:34:58 -07:00
|
|
|
} // namespace webrtc
|