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/encoder.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 <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2016-04-27 01:54:20 -07:00
|
|
|
#if defined(WEBRTC_IOS)
|
2016-08-03 12:57:09 -07:00
|
|
|
#import "WebRTC/UIDevice+RTCDevice.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 "Common/RTCUIApplication.h"
|
2016-04-27 01:54:20 -07:00
|
|
|
#endif
|
2015-06-29 14:34:58 -07:00
|
|
|
#include "libyuv/convert_from.h"
|
|
|
|
|
#include "webrtc/base/checks.h"
|
|
|
|
|
#include "webrtc/base/logging.h"
|
2016-11-15 09:56:55 -08:00
|
|
|
#include "webrtc/common_video/h264/profile_level_id.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/Video/corevideo_frame_buffer.h"
|
|
|
|
|
#include "webrtc/sdk/objc/Framework/Classes/VideoToolbox/nalu_rewriter.h"
|
2016-02-23 22:49:42 -08:00
|
|
|
#include "webrtc/system_wrappers/include/clock.h"
|
2015-06-29 14:34:58 -07:00
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
2016-07-26 03:10:33 -07:00
|
|
|
// The ratio between kVTCompressionPropertyKey_DataRateLimits and
|
|
|
|
|
// kVTCompressionPropertyKey_AverageBitRate. The data rate limit is set higher
|
|
|
|
|
// than the average bit rate to avoid undershooting the target.
|
|
|
|
|
const float kLimitToAverageBitRateFactor = 1.5f;
|
2016-09-28 08:17:43 -07:00
|
|
|
// These thresholds deviate from the default h264 QP thresholds, as they
|
|
|
|
|
// have been found to work better on devices that support VideoToolbox
|
|
|
|
|
const int kLowH264QpThreshold = 28;
|
|
|
|
|
const int kHighH264QpThreshold = 39;
|
2016-07-26 03:10:33 -07:00
|
|
|
|
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(kCFAllocatorDefault, keys, values, size,
|
|
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copies characters from a CFStringRef into a std::string.
|
|
|
|
|
std::string CFStringToString(const CFStringRef cf_string) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(cf_string);
|
2015-06-29 14:34:58 -07:00
|
|
|
std::string std_string;
|
|
|
|
|
// Get the size needed for UTF8 plus terminating character.
|
|
|
|
|
size_t buffer_size =
|
|
|
|
|
CFStringGetMaximumSizeForEncoding(CFStringGetLength(cf_string),
|
|
|
|
|
kCFStringEncodingUTF8) +
|
|
|
|
|
1;
|
2016-02-29 05:51:59 -08:00
|
|
|
std::unique_ptr<char[]> buffer(new char[buffer_size]);
|
2015-06-29 14:34:58 -07:00
|
|
|
if (CFStringGetCString(cf_string, buffer.get(), buffer_size,
|
|
|
|
|
kCFStringEncodingUTF8)) {
|
|
|
|
|
// Copy over the characters.
|
|
|
|
|
std_string.assign(buffer.get());
|
|
|
|
|
}
|
|
|
|
|
return std_string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convenience function for setting a VT property.
|
|
|
|
|
void SetVTSessionProperty(VTSessionRef session,
|
|
|
|
|
CFStringRef key,
|
|
|
|
|
int32_t value) {
|
|
|
|
|
CFNumberRef cfNum =
|
|
|
|
|
CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value);
|
|
|
|
|
OSStatus status = VTSessionSetProperty(session, key, cfNum);
|
|
|
|
|
CFRelease(cfNum);
|
|
|
|
|
if (status != noErr) {
|
|
|
|
|
std::string key_string = CFStringToString(key);
|
|
|
|
|
LOG(LS_ERROR) << "VTSessionSetProperty failed to set: " << key_string
|
|
|
|
|
<< " to " << value << ": " << status;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 22:49:42 -08:00
|
|
|
// Convenience function for setting a VT property.
|
|
|
|
|
void SetVTSessionProperty(VTSessionRef session,
|
|
|
|
|
CFStringRef key,
|
|
|
|
|
uint32_t value) {
|
|
|
|
|
int64_t value_64 = value;
|
|
|
|
|
CFNumberRef cfNum =
|
|
|
|
|
CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value_64);
|
|
|
|
|
OSStatus status = VTSessionSetProperty(session, key, cfNum);
|
|
|
|
|
CFRelease(cfNum);
|
|
|
|
|
if (status != noErr) {
|
|
|
|
|
std::string key_string = CFStringToString(key);
|
|
|
|
|
LOG(LS_ERROR) << "VTSessionSetProperty failed to set: " << key_string
|
|
|
|
|
<< " to " << value << ": " << status;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-29 14:34:58 -07:00
|
|
|
// Convenience function for setting a VT property.
|
|
|
|
|
void SetVTSessionProperty(VTSessionRef session, CFStringRef key, bool value) {
|
|
|
|
|
CFBooleanRef cf_bool = (value) ? kCFBooleanTrue : kCFBooleanFalse;
|
|
|
|
|
OSStatus status = VTSessionSetProperty(session, key, cf_bool);
|
|
|
|
|
if (status != noErr) {
|
|
|
|
|
std::string key_string = CFStringToString(key);
|
|
|
|
|
LOG(LS_ERROR) << "VTSessionSetProperty failed to set: " << key_string
|
|
|
|
|
<< " to " << value << ": " << status;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convenience function for setting a VT property.
|
|
|
|
|
void SetVTSessionProperty(VTSessionRef session,
|
|
|
|
|
CFStringRef key,
|
|
|
|
|
CFStringRef value) {
|
|
|
|
|
OSStatus status = VTSessionSetProperty(session, key, value);
|
|
|
|
|
if (status != noErr) {
|
|
|
|
|
std::string key_string = CFStringToString(key);
|
|
|
|
|
std::string val_string = CFStringToString(value);
|
|
|
|
|
LOG(LS_ERROR) << "VTSessionSetProperty failed to set: " << key_string
|
|
|
|
|
<< " to " << val_string << ": " << status;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Struct that we pass to the encoder per frame to encode. We receive it again
|
|
|
|
|
// in the encoder callback.
|
|
|
|
|
struct FrameEncodeParams {
|
2016-02-23 22:49:42 -08:00
|
|
|
FrameEncodeParams(webrtc::H264VideoToolboxEncoder* e,
|
2015-06-29 14:34:58 -07:00
|
|
|
const webrtc::CodecSpecificInfo* csi,
|
|
|
|
|
int32_t w,
|
|
|
|
|
int32_t h,
|
|
|
|
|
int64_t rtms,
|
2016-04-19 15:01:23 +02:00
|
|
|
uint32_t ts,
|
|
|
|
|
webrtc::VideoRotation r)
|
|
|
|
|
: encoder(e),
|
|
|
|
|
width(w),
|
|
|
|
|
height(h),
|
|
|
|
|
render_time_ms(rtms),
|
|
|
|
|
timestamp(ts),
|
|
|
|
|
rotation(r) {
|
2015-06-29 14:34:58 -07:00
|
|
|
if (csi) {
|
|
|
|
|
codec_specific_info = *csi;
|
|
|
|
|
} else {
|
|
|
|
|
codec_specific_info.codecType = webrtc::kVideoCodecH264;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-23 22:49:42 -08:00
|
|
|
|
|
|
|
|
webrtc::H264VideoToolboxEncoder* encoder;
|
2015-06-29 14:34:58 -07:00
|
|
|
webrtc::CodecSpecificInfo codec_specific_info;
|
|
|
|
|
int32_t width;
|
|
|
|
|
int32_t height;
|
|
|
|
|
int64_t render_time_ms;
|
|
|
|
|
uint32_t timestamp;
|
2016-04-19 15:01:23 +02:00
|
|
|
webrtc::VideoRotation rotation;
|
2015-06-29 14:34:58 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// We receive I420Frames as input, but we need to feed CVPixelBuffers into the
|
|
|
|
|
// encoder. This performs the copy and format conversion.
|
|
|
|
|
// TODO(tkchin): See if encoder will accept i420 frames and compare performance.
|
2017-06-12 15:09:48 +02:00
|
|
|
bool CopyVideoFrameToPixelBuffer(const rtc::scoped_refptr<webrtc::I420BufferInterface>& frame,
|
|
|
|
|
CVPixelBufferRef pixel_buffer) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(pixel_buffer);
|
2016-08-20 10:53:26 -07:00
|
|
|
RTC_DCHECK_EQ(CVPixelBufferGetPixelFormatType(pixel_buffer),
|
|
|
|
|
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange);
|
|
|
|
|
RTC_DCHECK_EQ(CVPixelBufferGetHeightOfPlane(pixel_buffer, 0),
|
|
|
|
|
static_cast<size_t>(frame->height()));
|
|
|
|
|
RTC_DCHECK_EQ(CVPixelBufferGetWidthOfPlane(pixel_buffer, 0),
|
|
|
|
|
static_cast<size_t>(frame->width()));
|
2015-06-29 14:34:58 -07:00
|
|
|
|
|
|
|
|
CVReturn cvRet = CVPixelBufferLockBaseAddress(pixel_buffer, 0);
|
|
|
|
|
if (cvRet != kCVReturnSuccess) {
|
|
|
|
|
LOG(LS_ERROR) << "Failed to lock base address: " << cvRet;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint8_t* dst_y = reinterpret_cast<uint8_t*>(
|
2015-06-29 14:34:58 -07:00
|
|
|
CVPixelBufferGetBaseAddressOfPlane(pixel_buffer, 0));
|
|
|
|
|
int dst_stride_y = CVPixelBufferGetBytesPerRowOfPlane(pixel_buffer, 0);
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint8_t* dst_uv = reinterpret_cast<uint8_t*>(
|
2015-06-29 14:34:58 -07:00
|
|
|
CVPixelBufferGetBaseAddressOfPlane(pixel_buffer, 1));
|
|
|
|
|
int dst_stride_uv = CVPixelBufferGetBytesPerRowOfPlane(pixel_buffer, 1);
|
|
|
|
|
// Convert I420 to NV12.
|
|
|
|
|
int ret = libyuv::I420ToNV12(
|
2016-06-13 13:06:01 +02:00
|
|
|
frame->DataY(), frame->StrideY(),
|
|
|
|
|
frame->DataU(), frame->StrideU(),
|
|
|
|
|
frame->DataV(), frame->StrideV(),
|
Reland of Delete webrtc::VideoFrame methods buffer and stride. (patchset #1 id:1 of https://codereview.webrtc.org/1983583002/ )
Reason for revert:
Should work after cl https://codereview.webrtc.org/1985693002/ is landed, which initializes the frames used by FakeWebRtcVideoCaptureModule. So intend to reland after that, with no changes.
Original issue's description:
> Revert of Delete webrtc::VideoFrame methods buffer and stride. (patchset #2 id:290001 of https://codereview.webrtc.org/1963413004/ )
>
> Reason for revert:
> Speculative revert to see if failures on the DrMemory bot are related to this cl. See e.g. here:
> https://build.chromium.org/p/client.webrtc/builders/Win%20DrMemory%20Full/builds/4243
>
> UNINITIALIZED READ: reading 0x04980040-0x04980060 32 byte(s) within 0x04980040-0x04980060
> # 0 CopyRow_AVX
> # 1 CopyPlane
> # 2 I420Copy
> # 3 webrtc::ExtractBuffer
> # 4 cricket::WebRtcVideoCapturer::SignalFrameCapturedOnStartThread
> # 5 cricket::WebRtcVideoCapturer::OnIncomingCapturedFrame
> # 6 FakeWebRtcVideoCaptureModule::SendFrame
> # 7 WebRtcVideoCapturerTest_TestCaptureVcm_Test::TestBody
> # 8 testing::internal::HandleSehExceptionsInMethodIfSupported<>
>
> Original issue's description:
> > Reland of Delete webrtc::VideoFrame methods buffer and stride. (patchset #1 id:1 of https://codereview.webrtc.org/1935443002/ )
> >
> > Reason for revert:
> > I plan to reland this change in a week or two, after downstream users are updated.
> >
> > Original issue's description:
> > > Revert of Delete webrtc::VideoFrame methods buffer and stride. (patchset #14 id:250001 of https://codereview.webrtc.org/1900673002/ )
> > >
> > > Reason for revert:
> > > Breaks chrome FYI bots.
> > >
> > > Original issue's description:
> > > > Delete webrtc::VideoFrame methods buffer and stride.
> > > >
> > > > To make the HasOneRef/IsMutable hack work, also had to change the
> > > > video_frame_buffer method to return a const ref to a scoped_ref_ptr,
> > > > to not imply an AddRef.
> > > >
> > > > BUG=webrtc:5682
> > >
> > > TBR=perkj@webrtc.org,magjed@webrtc.org,pbos@webrtc.org,pthatcher@webrtc.org,stefan@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:5682
> > >
> > > Committed: https://crrev.com/5b3c443d301f2c2f18dac5b02652c08b91ea3828
> > > Cr-Commit-Position: refs/heads/master@{#12558}
> >
> > TBR=perkj@webrtc.org,magjed@webrtc.org,pbos@webrtc.org,pthatcher@webrtc.org,stefan@webrtc.org
> > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > BUG=webrtc:5682
> >
> > Committed: https://crrev.com/d0dc66e0ea30c8614001e425a4ae0aa7dd56c2a7
> > Cr-Commit-Position: refs/heads/master@{#12721}
>
> TBR=perkj@webrtc.org,magjed@webrtc.org,pbos@webrtc.org,pthatcher@webrtc.org,stefan@webrtc.org,nisse@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5682
>
> Committed: https://crrev.com/d49c30cd2fe442f2b5b4ecec8d5cbaa430464725
> Cr-Commit-Position: refs/heads/master@{#12745}
TBR=perkj@webrtc.org,magjed@webrtc.org,pbos@webrtc.org,pthatcher@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5682
Review-Url: https://codereview.webrtc.org/1979193003
Cr-Commit-Position: refs/heads/master@{#12773}
2016-05-17 04:05:47 -07:00
|
|
|
dst_y, dst_stride_y, dst_uv, dst_stride_uv,
|
2016-06-13 13:06:01 +02:00
|
|
|
frame->width(), frame->height());
|
2015-06-29 14:34:58 -07:00
|
|
|
CVPixelBufferUnlockBaseAddress(pixel_buffer, 0);
|
|
|
|
|
if (ret) {
|
|
|
|
|
LOG(LS_ERROR) << "Error converting I420 VideoFrame to NV12 :" << ret;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-20 03:34:29 -07:00
|
|
|
CVPixelBufferRef CreatePixelBuffer(CVPixelBufferPoolRef pixel_buffer_pool) {
|
|
|
|
|
if (!pixel_buffer_pool) {
|
|
|
|
|
LOG(LS_ERROR) << "Failed to get pixel buffer pool.";
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
CVPixelBufferRef pixel_buffer;
|
|
|
|
|
CVReturn ret = CVPixelBufferPoolCreatePixelBuffer(nullptr, pixel_buffer_pool,
|
|
|
|
|
&pixel_buffer);
|
|
|
|
|
if (ret != kCVReturnSuccess) {
|
|
|
|
|
LOG(LS_ERROR) << "Failed to create pixel buffer: " << ret;
|
|
|
|
|
// We probably want to drop frames here, since failure probably means
|
|
|
|
|
// that the pool is empty.
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
return pixel_buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-29 14:34:58 -07:00
|
|
|
// This is the callback function that VideoToolbox calls when encode is
|
2016-02-23 22:49:42 -08:00
|
|
|
// complete. From inspection this happens on its own queue.
|
2015-06-29 14:34:58 -07:00
|
|
|
void VTCompressionOutputCallback(void* encoder,
|
|
|
|
|
void* params,
|
|
|
|
|
OSStatus status,
|
|
|
|
|
VTEncodeInfoFlags info_flags,
|
|
|
|
|
CMSampleBufferRef sample_buffer) {
|
2016-02-29 05:51:59 -08:00
|
|
|
std::unique_ptr<FrameEncodeParams> encode_params(
|
2015-06-29 14:34:58 -07:00
|
|
|
reinterpret_cast<FrameEncodeParams*>(params));
|
2016-02-23 22:49:42 -08:00
|
|
|
encode_params->encoder->OnEncodedFrame(
|
|
|
|
|
status, info_flags, sample_buffer, encode_params->codec_specific_info,
|
|
|
|
|
encode_params->width, encode_params->height,
|
2016-04-19 15:01:23 +02:00
|
|
|
encode_params->render_time_ms, encode_params->timestamp,
|
|
|
|
|
encode_params->rotation);
|
2015-06-29 14:34:58 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-15 09:56:55 -08:00
|
|
|
// Extract VideoToolbox profile out of the cricket::VideoCodec. If there is no
|
|
|
|
|
// specific VideoToolbox profile for the specified level, AutoLevel will be
|
|
|
|
|
// returned. The user must initialize the encoder with a resolution and
|
|
|
|
|
// framerate conforming to the selected H264 level regardless.
|
|
|
|
|
CFStringRef ExtractProfile(const cricket::VideoCodec& codec) {
|
|
|
|
|
const rtc::Optional<webrtc::H264::ProfileLevelId> profile_level_id =
|
|
|
|
|
webrtc::H264::ParseSdpProfileLevelId(codec.params);
|
|
|
|
|
RTC_DCHECK(profile_level_id);
|
|
|
|
|
switch (profile_level_id->profile) {
|
|
|
|
|
case webrtc::H264::kProfileConstrainedBaseline:
|
|
|
|
|
case webrtc::H264::kProfileBaseline:
|
|
|
|
|
switch (profile_level_id->level) {
|
|
|
|
|
case webrtc::H264::kLevel3:
|
|
|
|
|
return kVTProfileLevel_H264_Baseline_3_0;
|
|
|
|
|
case webrtc::H264::kLevel3_1:
|
|
|
|
|
return kVTProfileLevel_H264_Baseline_3_1;
|
|
|
|
|
case webrtc::H264::kLevel3_2:
|
|
|
|
|
return kVTProfileLevel_H264_Baseline_3_2;
|
|
|
|
|
case webrtc::H264::kLevel4:
|
|
|
|
|
return kVTProfileLevel_H264_Baseline_4_0;
|
|
|
|
|
case webrtc::H264::kLevel4_1:
|
|
|
|
|
return kVTProfileLevel_H264_Baseline_4_1;
|
|
|
|
|
case webrtc::H264::kLevel4_2:
|
|
|
|
|
return kVTProfileLevel_H264_Baseline_4_2;
|
|
|
|
|
case webrtc::H264::kLevel5:
|
|
|
|
|
return kVTProfileLevel_H264_Baseline_5_0;
|
|
|
|
|
case webrtc::H264::kLevel5_1:
|
|
|
|
|
return kVTProfileLevel_H264_Baseline_5_1;
|
|
|
|
|
case webrtc::H264::kLevel5_2:
|
|
|
|
|
return kVTProfileLevel_H264_Baseline_5_2;
|
|
|
|
|
case webrtc::H264::kLevel1:
|
|
|
|
|
case webrtc::H264::kLevel1_b:
|
|
|
|
|
case webrtc::H264::kLevel1_1:
|
|
|
|
|
case webrtc::H264::kLevel1_2:
|
|
|
|
|
case webrtc::H264::kLevel1_3:
|
|
|
|
|
case webrtc::H264::kLevel2:
|
|
|
|
|
case webrtc::H264::kLevel2_1:
|
|
|
|
|
case webrtc::H264::kLevel2_2:
|
|
|
|
|
return kVTProfileLevel_H264_Baseline_AutoLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case webrtc::H264::kProfileMain:
|
|
|
|
|
switch (profile_level_id->level) {
|
|
|
|
|
case webrtc::H264::kLevel3:
|
|
|
|
|
return kVTProfileLevel_H264_Main_3_0;
|
|
|
|
|
case webrtc::H264::kLevel3_1:
|
|
|
|
|
return kVTProfileLevel_H264_Main_3_1;
|
|
|
|
|
case webrtc::H264::kLevel3_2:
|
|
|
|
|
return kVTProfileLevel_H264_Main_3_2;
|
|
|
|
|
case webrtc::H264::kLevel4:
|
|
|
|
|
return kVTProfileLevel_H264_Main_4_0;
|
|
|
|
|
case webrtc::H264::kLevel4_1:
|
|
|
|
|
return kVTProfileLevel_H264_Main_4_1;
|
|
|
|
|
case webrtc::H264::kLevel4_2:
|
|
|
|
|
return kVTProfileLevel_H264_Main_4_2;
|
|
|
|
|
case webrtc::H264::kLevel5:
|
|
|
|
|
return kVTProfileLevel_H264_Main_5_0;
|
|
|
|
|
case webrtc::H264::kLevel5_1:
|
|
|
|
|
return kVTProfileLevel_H264_Main_5_1;
|
|
|
|
|
case webrtc::H264::kLevel5_2:
|
|
|
|
|
return kVTProfileLevel_H264_Main_5_2;
|
|
|
|
|
case webrtc::H264::kLevel1:
|
|
|
|
|
case webrtc::H264::kLevel1_b:
|
|
|
|
|
case webrtc::H264::kLevel1_1:
|
|
|
|
|
case webrtc::H264::kLevel1_2:
|
|
|
|
|
case webrtc::H264::kLevel1_3:
|
|
|
|
|
case webrtc::H264::kLevel2:
|
|
|
|
|
case webrtc::H264::kLevel2_1:
|
|
|
|
|
case webrtc::H264::kLevel2_2:
|
|
|
|
|
return kVTProfileLevel_H264_Main_AutoLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case webrtc::H264::kProfileConstrainedHigh:
|
|
|
|
|
case webrtc::H264::kProfileHigh:
|
|
|
|
|
switch (profile_level_id->level) {
|
|
|
|
|
case webrtc::H264::kLevel3:
|
|
|
|
|
return kVTProfileLevel_H264_High_3_0;
|
|
|
|
|
case webrtc::H264::kLevel3_1:
|
|
|
|
|
return kVTProfileLevel_H264_High_3_1;
|
|
|
|
|
case webrtc::H264::kLevel3_2:
|
|
|
|
|
return kVTProfileLevel_H264_High_3_2;
|
|
|
|
|
case webrtc::H264::kLevel4:
|
|
|
|
|
return kVTProfileLevel_H264_High_4_0;
|
|
|
|
|
case webrtc::H264::kLevel4_1:
|
|
|
|
|
return kVTProfileLevel_H264_High_4_1;
|
|
|
|
|
case webrtc::H264::kLevel4_2:
|
|
|
|
|
return kVTProfileLevel_H264_High_4_2;
|
|
|
|
|
case webrtc::H264::kLevel5:
|
|
|
|
|
return kVTProfileLevel_H264_High_5_0;
|
|
|
|
|
case webrtc::H264::kLevel5_1:
|
|
|
|
|
return kVTProfileLevel_H264_High_5_1;
|
|
|
|
|
case webrtc::H264::kLevel5_2:
|
|
|
|
|
return kVTProfileLevel_H264_High_5_2;
|
|
|
|
|
case webrtc::H264::kLevel1:
|
|
|
|
|
case webrtc::H264::kLevel1_b:
|
|
|
|
|
case webrtc::H264::kLevel1_1:
|
|
|
|
|
case webrtc::H264::kLevel1_2:
|
|
|
|
|
case webrtc::H264::kLevel1_3:
|
|
|
|
|
case webrtc::H264::kLevel2:
|
|
|
|
|
case webrtc::H264::kLevel2_1:
|
|
|
|
|
case webrtc::H264::kLevel2_2:
|
|
|
|
|
return kVTProfileLevel_H264_High_AutoLevel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-29 14:34:58 -07:00
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2016-02-23 22:49:42 -08:00
|
|
|
// .5 is set as a mininum to prevent overcompensating for large temporary
|
|
|
|
|
// overshoots. We don't want to degrade video quality too badly.
|
|
|
|
|
// .95 is set to prevent oscillations. When a lower bitrate is set on the
|
|
|
|
|
// encoder than previously set, its output seems to have a brief period of
|
|
|
|
|
// drastically reduced bitrate, so we want to avoid that. In steady state
|
|
|
|
|
// conditions, 0.95 seems to give us better overall bitrate over long periods
|
|
|
|
|
// of time.
|
2016-12-16 02:10:20 -08:00
|
|
|
H264VideoToolboxEncoder::H264VideoToolboxEncoder(const cricket::VideoCodec& codec)
|
2016-02-23 22:49:42 -08:00
|
|
|
: callback_(nullptr),
|
|
|
|
|
compression_session_(nullptr),
|
2016-11-15 09:56:55 -08:00
|
|
|
bitrate_adjuster_(Clock::GetRealTimeClock(), .5, .95),
|
2016-12-16 02:10:20 -08:00
|
|
|
packetization_mode_(H264PacketizationMode::NonInterleaved),
|
2016-11-15 09:56:55 -08:00
|
|
|
profile_(internal::ExtractProfile(codec)) {
|
|
|
|
|
LOG(LS_INFO) << "Using profile " << internal::CFStringToString(profile_);
|
2016-12-16 02:10:20 -08:00
|
|
|
RTC_CHECK(cricket::CodecNamesEq(codec.name, cricket::kH264CodecName));
|
2016-08-03 12:57:09 -07:00
|
|
|
}
|
2015-06-29 14:34:58 -07:00
|
|
|
|
|
|
|
|
H264VideoToolboxEncoder::~H264VideoToolboxEncoder() {
|
|
|
|
|
DestroyCompressionSession();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int H264VideoToolboxEncoder::InitEncode(const VideoCodec* codec_settings,
|
|
|
|
|
int number_of_cores,
|
|
|
|
|
size_t max_payload_size) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(codec_settings);
|
|
|
|
|
RTC_DCHECK_EQ(codec_settings->codecType, kVideoCodecH264);
|
2016-11-29 01:44:11 -08:00
|
|
|
|
|
|
|
|
width_ = codec_settings->width;
|
|
|
|
|
height_ = codec_settings->height;
|
2017-04-11 10:34:31 -07:00
|
|
|
mode_ = codec_settings->mode;
|
2015-06-29 14:34:58 -07:00
|
|
|
// We can only set average bitrate on the HW encoder.
|
2016-02-23 22:49:42 -08:00
|
|
|
target_bitrate_bps_ = codec_settings->startBitrate;
|
|
|
|
|
bitrate_adjuster_.SetTargetBitrateBps(target_bitrate_bps_);
|
2015-06-29 14:34:58 -07:00
|
|
|
|
|
|
|
|
// TODO(tkchin): Try setting payload size via
|
|
|
|
|
// kVTCompressionPropertyKey_MaxH264SliceBytes.
|
|
|
|
|
|
|
|
|
|
return ResetCompressionSession();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int H264VideoToolboxEncoder::Encode(
|
2016-05-24 12:21:58 +02:00
|
|
|
const VideoFrame& frame,
|
2015-06-29 14:34:58 -07:00
|
|
|
const CodecSpecificInfo* codec_specific_info,
|
2015-10-19 02:39:06 -07:00
|
|
|
const std::vector<FrameType>* frame_types) {
|
2016-11-29 01:44:11 -08:00
|
|
|
// |input_frame| size should always match codec settings.
|
|
|
|
|
RTC_DCHECK_EQ(frame.width(), width_);
|
|
|
|
|
RTC_DCHECK_EQ(frame.height(), height_);
|
2015-06-29 14:34:58 -07:00
|
|
|
if (!callback_ || !compression_session_) {
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
|
|
|
|
}
|
2016-03-08 10:51:54 -08:00
|
|
|
#if defined(WEBRTC_IOS)
|
|
|
|
|
if (!RTCIsUIApplicationActive()) {
|
|
|
|
|
// Ignore all encode requests when app isn't active. In this state, the
|
|
|
|
|
// hardware encoder has been invalidated by the OS.
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2016-04-11 11:40:25 -07:00
|
|
|
bool is_keyframe_required = false;
|
2016-05-24 12:21:58 +02:00
|
|
|
|
2016-08-09 13:02:00 -07:00
|
|
|
// Get a pixel buffer from the pool and copy frame data over.
|
|
|
|
|
CVPixelBufferPoolRef pixel_buffer_pool =
|
|
|
|
|
VTCompressionSessionGetPixelBufferPool(compression_session_);
|
|
|
|
|
#if defined(WEBRTC_IOS)
|
|
|
|
|
if (!pixel_buffer_pool) {
|
|
|
|
|
// Kind of a hack. On backgrounding, the compression session seems to get
|
|
|
|
|
// invalidated, which causes this pool call to fail when the application
|
|
|
|
|
// is foregrounded and frames are being sent for encoding again.
|
|
|
|
|
// Resetting the session when this happens fixes the issue.
|
|
|
|
|
// In addition we request a keyframe so video can recover quickly.
|
|
|
|
|
ResetCompressionSession();
|
|
|
|
|
pixel_buffer_pool =
|
|
|
|
|
VTCompressionSessionGetPixelBufferPool(compression_session_);
|
|
|
|
|
is_keyframe_required = true;
|
|
|
|
|
LOG(LS_INFO) << "Resetting compression session due to invalid pool.";
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-06-12 15:09:48 +02:00
|
|
|
CVPixelBufferRef pixel_buffer;
|
|
|
|
|
if (frame.video_frame_buffer()->type() == VideoFrameBuffer::Type::kNative) {
|
2016-10-20 03:34:29 -07:00
|
|
|
rtc::scoped_refptr<CoreVideoFrameBuffer> core_video_frame_buffer(
|
|
|
|
|
static_cast<CoreVideoFrameBuffer*>(frame.video_frame_buffer().get()));
|
|
|
|
|
if (!core_video_frame_buffer->RequiresCropping()) {
|
2017-06-12 15:09:48 +02:00
|
|
|
pixel_buffer = core_video_frame_buffer->pixel_buffer();
|
2016-10-20 03:34:29 -07:00
|
|
|
// This pixel buffer might have a higher resolution than what the
|
|
|
|
|
// compression session is configured to. The compression session can
|
|
|
|
|
// handle that and will output encoded frames in the configured
|
|
|
|
|
// resolution regardless of the input pixel buffer resolution.
|
|
|
|
|
CVBufferRetain(pixel_buffer);
|
|
|
|
|
} else {
|
|
|
|
|
// Cropping required, we need to crop and scale to a new pixel buffer.
|
|
|
|
|
pixel_buffer = internal::CreatePixelBuffer(pixel_buffer_pool);
|
|
|
|
|
if (!pixel_buffer) {
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
|
|
|
|
if (!core_video_frame_buffer->CropAndScaleTo(&nv12_scale_buffer_,
|
|
|
|
|
pixel_buffer)) {
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
2016-07-12 01:26:42 -07:00
|
|
|
}
|
2016-10-20 03:34:29 -07:00
|
|
|
} else {
|
|
|
|
|
pixel_buffer = internal::CreatePixelBuffer(pixel_buffer_pool);
|
|
|
|
|
if (!pixel_buffer) {
|
2016-07-12 01:26:42 -07:00
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
2016-11-29 01:44:11 -08:00
|
|
|
RTC_DCHECK(pixel_buffer);
|
2017-06-12 15:09:48 +02:00
|
|
|
if (!internal::CopyVideoFrameToPixelBuffer(frame.video_frame_buffer()->ToI420(),
|
2016-08-20 10:53:26 -07:00
|
|
|
pixel_buffer)) {
|
2016-07-12 01:26:42 -07:00
|
|
|
LOG(LS_ERROR) << "Failed to copy frame data.";
|
|
|
|
|
CVBufferRelease(pixel_buffer);
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
2015-06-29 14:34:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if we need a keyframe.
|
2016-04-11 11:40:25 -07:00
|
|
|
if (!is_keyframe_required && frame_types) {
|
2015-06-29 14:34:58 -07:00
|
|
|
for (auto frame_type : *frame_types) {
|
2015-10-23 15:58:18 +02:00
|
|
|
if (frame_type == kVideoFrameKey) {
|
2015-06-29 14:34:58 -07:00
|
|
|
is_keyframe_required = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMTime presentation_time_stamp =
|
2016-06-13 13:06:01 +02:00
|
|
|
CMTimeMake(frame.render_time_ms(), 1000);
|
2015-06-29 14:34:58 -07:00
|
|
|
CFDictionaryRef frame_properties = nullptr;
|
|
|
|
|
if (is_keyframe_required) {
|
2015-12-21 03:04:49 -08:00
|
|
|
CFTypeRef keys[] = {kVTEncodeFrameOptionKey_ForceKeyFrame};
|
|
|
|
|
CFTypeRef values[] = {kCFBooleanTrue};
|
2015-06-29 14:34:58 -07:00
|
|
|
frame_properties = internal::CreateCFDictionary(keys, values, 1);
|
|
|
|
|
}
|
2016-02-29 05:51:59 -08:00
|
|
|
std::unique_ptr<internal::FrameEncodeParams> encode_params;
|
2015-06-29 14:34:58 -07:00
|
|
|
encode_params.reset(new internal::FrameEncodeParams(
|
2016-06-13 13:06:01 +02:00
|
|
|
this, codec_specific_info, width_, height_, frame.render_time_ms(),
|
|
|
|
|
frame.timestamp(), frame.rotation()));
|
2016-02-23 22:49:42 -08:00
|
|
|
|
2016-12-16 02:10:20 -08:00
|
|
|
encode_params->codec_specific_info.codecSpecific.H264.packetization_mode =
|
|
|
|
|
packetization_mode_;
|
|
|
|
|
|
2016-02-23 22:49:42 -08:00
|
|
|
// Update the bitrate if needed.
|
|
|
|
|
SetBitrateBps(bitrate_adjuster_.GetAdjustedBitrateBps());
|
|
|
|
|
|
2016-03-08 10:51:54 -08:00
|
|
|
OSStatus status = VTCompressionSessionEncodeFrame(
|
2015-06-29 14:34:58 -07:00
|
|
|
compression_session_, pixel_buffer, presentation_time_stamp,
|
|
|
|
|
kCMTimeInvalid, frame_properties, encode_params.release(), nullptr);
|
|
|
|
|
if (frame_properties) {
|
|
|
|
|
CFRelease(frame_properties);
|
|
|
|
|
}
|
|
|
|
|
if (pixel_buffer) {
|
|
|
|
|
CVBufferRelease(pixel_buffer);
|
|
|
|
|
}
|
2016-03-08 10:51:54 -08:00
|
|
|
if (status != noErr) {
|
|
|
|
|
LOG(LS_ERROR) << "Failed to encode frame with code: " << status;
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
2015-06-29 14:34:58 -07:00
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int H264VideoToolboxEncoder::RegisterEncodeCompleteCallback(
|
|
|
|
|
EncodedImageCallback* callback) {
|
|
|
|
|
callback_ = callback;
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int H264VideoToolboxEncoder::SetChannelParameters(uint32_t packet_loss,
|
|
|
|
|
int64_t rtt) {
|
|
|
|
|
// Encoder doesn't know anything about packet loss or rtt so just return.
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int H264VideoToolboxEncoder::SetRates(uint32_t new_bitrate_kbit,
|
|
|
|
|
uint32_t frame_rate) {
|
2016-02-23 22:49:42 -08:00
|
|
|
target_bitrate_bps_ = 1000 * new_bitrate_kbit;
|
|
|
|
|
bitrate_adjuster_.SetTargetBitrateBps(target_bitrate_bps_);
|
|
|
|
|
SetBitrateBps(bitrate_adjuster_.GetAdjustedBitrateBps());
|
2015-06-29 14:34:58 -07:00
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int H264VideoToolboxEncoder::Release() {
|
2016-02-23 22:49:42 -08:00
|
|
|
// Need to reset so that the session is invalidated and won't use the
|
|
|
|
|
// callback anymore. Do not remove callback until the session is invalidated
|
|
|
|
|
// since async encoder callbacks can occur until invalidation.
|
|
|
|
|
int ret = ResetCompressionSession();
|
2015-06-29 14:34:58 -07:00
|
|
|
callback_ = nullptr;
|
2016-02-23 22:49:42 -08:00
|
|
|
return ret;
|
2015-06-29 14:34:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int H264VideoToolboxEncoder::ResetCompressionSession() {
|
|
|
|
|
DestroyCompressionSession();
|
|
|
|
|
|
|
|
|
|
// Set source image buffer attributes. These attributes will be present on
|
|
|
|
|
// buffers retrieved from the encoder's pixel buffer pool.
|
|
|
|
|
const size_t attributes_size = 3;
|
|
|
|
|
CFTypeRef keys[attributes_size] = {
|
|
|
|
|
#if defined(WEBRTC_IOS)
|
|
|
|
|
kCVPixelBufferOpenGLESCompatibilityKey,
|
|
|
|
|
#elif defined(WEBRTC_MAC)
|
|
|
|
|
kCVPixelBufferOpenGLCompatibilityKey,
|
|
|
|
|
#endif
|
|
|
|
|
kCVPixelBufferIOSurfacePropertiesKey,
|
|
|
|
|
kCVPixelBufferPixelFormatTypeKey
|
|
|
|
|
};
|
|
|
|
|
CFDictionaryRef io_surface_value =
|
|
|
|
|
internal::CreateCFDictionary(nullptr, nullptr, 0);
|
|
|
|
|
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 source_attributes =
|
|
|
|
|
internal::CreateCFDictionary(keys, values, attributes_size);
|
|
|
|
|
if (io_surface_value) {
|
|
|
|
|
CFRelease(io_surface_value);
|
|
|
|
|
io_surface_value = nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (pixel_format) {
|
|
|
|
|
CFRelease(pixel_format);
|
|
|
|
|
pixel_format = nullptr;
|
|
|
|
|
}
|
|
|
|
|
OSStatus status = VTCompressionSessionCreate(
|
|
|
|
|
nullptr, // use default allocator
|
2015-12-21 03:04:49 -08:00
|
|
|
width_, height_, kCMVideoCodecType_H264,
|
2015-06-29 14:34:58 -07:00
|
|
|
nullptr, // use default encoder
|
|
|
|
|
source_attributes,
|
|
|
|
|
nullptr, // use default compressed data allocator
|
2015-12-21 03:04:49 -08:00
|
|
|
internal::VTCompressionOutputCallback, this, &compression_session_);
|
2015-06-29 14:34:58 -07:00
|
|
|
if (source_attributes) {
|
|
|
|
|
CFRelease(source_attributes);
|
|
|
|
|
source_attributes = nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (status != noErr) {
|
|
|
|
|
LOG(LS_ERROR) << "Failed to create compression session: " << status;
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
|
|
|
|
ConfigureCompressionSession();
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void H264VideoToolboxEncoder::ConfigureCompressionSession() {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(compression_session_);
|
2015-06-29 14:34:58 -07:00
|
|
|
internal::SetVTSessionProperty(compression_session_,
|
|
|
|
|
kVTCompressionPropertyKey_RealTime, true);
|
|
|
|
|
internal::SetVTSessionProperty(compression_session_,
|
|
|
|
|
kVTCompressionPropertyKey_ProfileLevel,
|
2016-11-15 09:56:55 -08:00
|
|
|
profile_);
|
2015-06-29 14:34:58 -07:00
|
|
|
internal::SetVTSessionProperty(compression_session_,
|
|
|
|
|
kVTCompressionPropertyKey_AllowFrameReordering,
|
|
|
|
|
false);
|
2016-02-23 22:49:42 -08:00
|
|
|
SetEncoderBitrateBps(target_bitrate_bps_);
|
2015-06-29 14:34:58 -07:00
|
|
|
// TODO(tkchin): Look at entropy mode and colorspace matrices.
|
|
|
|
|
// TODO(tkchin): Investigate to see if there's any way to make this work.
|
|
|
|
|
// May need it to interop with Android. Currently this call just fails.
|
|
|
|
|
// On inspecting encoder output on iOS8, this value is set to 6.
|
|
|
|
|
// internal::SetVTSessionProperty(compression_session_,
|
|
|
|
|
// kVTCompressionPropertyKey_MaxFrameDelayCount,
|
|
|
|
|
// 1);
|
2016-06-02 15:36:40 +02:00
|
|
|
|
|
|
|
|
// Set a relatively large value for keyframe emission (7200 frames or
|
|
|
|
|
// 4 minutes).
|
|
|
|
|
internal::SetVTSessionProperty(
|
|
|
|
|
compression_session_,
|
|
|
|
|
kVTCompressionPropertyKey_MaxKeyFrameInterval, 7200);
|
|
|
|
|
internal::SetVTSessionProperty(
|
|
|
|
|
compression_session_,
|
|
|
|
|
kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration, 240);
|
2015-06-29 14:34:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void H264VideoToolboxEncoder::DestroyCompressionSession() {
|
|
|
|
|
if (compression_session_) {
|
|
|
|
|
VTCompressionSessionInvalidate(compression_session_);
|
|
|
|
|
CFRelease(compression_session_);
|
|
|
|
|
compression_session_ = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-18 16:01:11 +01:00
|
|
|
const char* H264VideoToolboxEncoder::ImplementationName() const {
|
|
|
|
|
return "VideoToolbox";
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-12 01:26:42 -07:00
|
|
|
bool H264VideoToolboxEncoder::SupportsNativeHandle() const {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 22:49:42 -08:00
|
|
|
void H264VideoToolboxEncoder::SetBitrateBps(uint32_t bitrate_bps) {
|
|
|
|
|
if (encoder_bitrate_bps_ != bitrate_bps) {
|
|
|
|
|
SetEncoderBitrateBps(bitrate_bps);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void H264VideoToolboxEncoder::SetEncoderBitrateBps(uint32_t bitrate_bps) {
|
|
|
|
|
if (compression_session_) {
|
|
|
|
|
internal::SetVTSessionProperty(compression_session_,
|
|
|
|
|
kVTCompressionPropertyKey_AverageBitRate,
|
|
|
|
|
bitrate_bps);
|
2016-06-02 15:36:40 +02:00
|
|
|
|
|
|
|
|
// TODO(tkchin): Add a helper method to set array value.
|
2016-07-26 03:10:33 -07:00
|
|
|
int64_t data_limit_bytes_per_second_value = static_cast<int64_t>(
|
|
|
|
|
bitrate_bps * internal::kLimitToAverageBitRateFactor / 8);
|
2016-06-02 15:36:40 +02:00
|
|
|
CFNumberRef bytes_per_second =
|
|
|
|
|
CFNumberCreate(kCFAllocatorDefault,
|
|
|
|
|
kCFNumberSInt64Type,
|
2016-07-26 03:10:33 -07:00
|
|
|
&data_limit_bytes_per_second_value);
|
2016-06-02 15:36:40 +02:00
|
|
|
int64_t one_second_value = 1;
|
|
|
|
|
CFNumberRef one_second =
|
|
|
|
|
CFNumberCreate(kCFAllocatorDefault,
|
|
|
|
|
kCFNumberSInt64Type,
|
|
|
|
|
&one_second_value);
|
|
|
|
|
const void* nums[2] = { bytes_per_second, one_second };
|
|
|
|
|
CFArrayRef data_rate_limits =
|
|
|
|
|
CFArrayCreate(nullptr, nums, 2, &kCFTypeArrayCallBacks);
|
|
|
|
|
OSStatus status =
|
|
|
|
|
VTSessionSetProperty(compression_session_,
|
|
|
|
|
kVTCompressionPropertyKey_DataRateLimits,
|
|
|
|
|
data_rate_limits);
|
|
|
|
|
if (bytes_per_second) {
|
|
|
|
|
CFRelease(bytes_per_second);
|
|
|
|
|
}
|
|
|
|
|
if (one_second) {
|
|
|
|
|
CFRelease(one_second);
|
|
|
|
|
}
|
|
|
|
|
if (data_rate_limits) {
|
|
|
|
|
CFRelease(data_rate_limits);
|
|
|
|
|
}
|
|
|
|
|
if (status != noErr) {
|
|
|
|
|
LOG(LS_ERROR) << "Failed to set data rate limit";
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 22:49:42 -08:00
|
|
|
encoder_bitrate_bps_ = bitrate_bps;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void H264VideoToolboxEncoder::OnEncodedFrame(
|
|
|
|
|
OSStatus status,
|
|
|
|
|
VTEncodeInfoFlags info_flags,
|
|
|
|
|
CMSampleBufferRef sample_buffer,
|
|
|
|
|
CodecSpecificInfo codec_specific_info,
|
|
|
|
|
int32_t width,
|
|
|
|
|
int32_t height,
|
|
|
|
|
int64_t render_time_ms,
|
2016-04-19 15:01:23 +02:00
|
|
|
uint32_t timestamp,
|
|
|
|
|
VideoRotation rotation) {
|
2016-02-23 22:49:42 -08:00
|
|
|
if (status != noErr) {
|
|
|
|
|
LOG(LS_ERROR) << "H264 encode failed.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (info_flags & kVTEncodeInfo_FrameDropped) {
|
|
|
|
|
LOG(LS_INFO) << "H264 encode dropped frame.";
|
2016-05-24 12:21:58 +02:00
|
|
|
return;
|
2016-02-23 22:49:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_keyframe = false;
|
|
|
|
|
CFArrayRef attachments =
|
|
|
|
|
CMSampleBufferGetSampleAttachmentsArray(sample_buffer, 0);
|
|
|
|
|
if (attachments != nullptr && CFArrayGetCount(attachments)) {
|
|
|
|
|
CFDictionaryRef attachment =
|
|
|
|
|
static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(attachments, 0));
|
|
|
|
|
is_keyframe =
|
|
|
|
|
!CFDictionaryContainsKey(attachment, kCMSampleAttachmentKey_NotSync);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-02 15:36:40 +02:00
|
|
|
if (is_keyframe) {
|
|
|
|
|
LOG(LS_INFO) << "Generated keyframe";
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 22:49:42 -08:00
|
|
|
// Convert the sample buffer into a buffer suitable for RTP packetization.
|
|
|
|
|
// TODO(tkchin): Allocate buffers through a pool.
|
2016-02-29 05:51:59 -08:00
|
|
|
std::unique_ptr<rtc::Buffer> buffer(new rtc::Buffer());
|
|
|
|
|
std::unique_ptr<webrtc::RTPFragmentationHeader> header;
|
|
|
|
|
{
|
|
|
|
|
webrtc::RTPFragmentationHeader* header_raw;
|
|
|
|
|
bool result = H264CMSampleBufferToAnnexBBuffer(sample_buffer, is_keyframe,
|
|
|
|
|
buffer.get(), &header_raw);
|
|
|
|
|
header.reset(header_raw);
|
|
|
|
|
if (!result) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-02-23 22:49:42 -08:00
|
|
|
}
|
|
|
|
|
webrtc::EncodedImage frame(buffer->data(), buffer->size(), buffer->size());
|
|
|
|
|
frame._encodedWidth = width;
|
|
|
|
|
frame._encodedHeight = height;
|
|
|
|
|
frame._completeFrame = true;
|
|
|
|
|
frame._frameType =
|
|
|
|
|
is_keyframe ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta;
|
|
|
|
|
frame.capture_time_ms_ = render_time_ms;
|
|
|
|
|
frame._timeStamp = timestamp;
|
2016-04-19 15:01:23 +02:00
|
|
|
frame.rotation_ = rotation;
|
2016-02-23 22:49:42 -08:00
|
|
|
|
2017-04-11 10:34:31 -07:00
|
|
|
frame.content_type_ =
|
|
|
|
|
(mode_ == kScreensharing) ? VideoContentType::SCREENSHARE : VideoContentType::UNSPECIFIED;
|
|
|
|
|
|
2016-05-24 12:21:58 +02:00
|
|
|
h264_bitstream_parser_.ParseBitstream(buffer->data(), buffer->size());
|
2016-11-29 01:44:11 -08:00
|
|
|
h264_bitstream_parser_.GetLastSliceQp(&frame.qp_);
|
2016-05-24 12:21:58 +02:00
|
|
|
|
2016-11-29 01:44:11 -08:00
|
|
|
EncodedImageCallback::Result res =
|
2016-11-04 11:39:29 -07:00
|
|
|
callback_->OnEncodedImage(frame, &codec_specific_info, header.get());
|
2016-11-29 01:44:11 -08:00
|
|
|
if (res.error != EncodedImageCallback::Result::OK) {
|
|
|
|
|
LOG(LS_ERROR) << "Encode callback failed: " << res.error;
|
2016-02-23 22:49:42 -08:00
|
|
|
return;
|
|
|
|
|
}
|
2017-01-10 03:02:04 -08:00
|
|
|
bitrate_adjuster_.Update(frame._length);
|
2016-02-23 22:49:42 -08:00
|
|
|
}
|
|
|
|
|
|
2016-11-29 01:44:11 -08:00
|
|
|
VideoEncoder::ScalingSettings H264VideoToolboxEncoder::GetScalingSettings()
|
|
|
|
|
const {
|
|
|
|
|
return VideoEncoder::ScalingSettings(true, internal::kLowH264QpThreshold,
|
|
|
|
|
internal::kHighH264QpThreshold);
|
|
|
|
|
}
|
2015-06-29 14:34:58 -07:00
|
|
|
} // namespace webrtc
|