2016-12-01 00:27:27 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "media/engine/internal_decoder_factory.h"
|
2016-12-01 00:27:27 -08:00
|
|
|
|
2018-10-23 10:07:25 +02:00
|
|
|
#include "absl/strings/match.h"
|
2018-01-30 10:32:13 +01:00
|
|
|
#include "api/video_codecs/sdp_video_format.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "media/base/codec.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "media/base/media_constants.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/codecs/h264/include/h264.h"
|
2018-05-14 10:11:42 +02:00
|
|
|
#include "modules/video_coding/codecs/vp8/include/vp8.h"
|
|
|
|
|
#include "modules/video_coding/codecs/vp9/include/vp9.h"
|
2017-11-09 13:43:42 +01:00
|
|
|
#include "rtc_base/checks.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/logging.h"
|
2016-12-01 00:27:27 -08:00
|
|
|
|
2017-11-09 13:43:42 +01:00
|
|
|
namespace webrtc {
|
|
|
|
|
|
2018-08-06 10:10:51 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
bool IsFormatSupported(
|
|
|
|
|
const std::vector<webrtc::SdpVideoFormat>& supported_formats,
|
|
|
|
|
const webrtc::SdpVideoFormat& format) {
|
|
|
|
|
for (const webrtc::SdpVideoFormat& supported_format : supported_formats) {
|
|
|
|
|
if (cricket::IsSameCodec(format.name, format.parameters,
|
|
|
|
|
supported_format.name,
|
|
|
|
|
supported_format.parameters)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2017-11-09 13:43:42 +01:00
|
|
|
std::vector<SdpVideoFormat> InternalDecoderFactory::GetSupportedFormats()
|
|
|
|
|
const {
|
|
|
|
|
std::vector<SdpVideoFormat> formats;
|
|
|
|
|
formats.push_back(SdpVideoFormat(cricket::kVp8CodecName));
|
2018-06-28 10:59:02 -07:00
|
|
|
for (const SdpVideoFormat& format : SupportedVP9Codecs())
|
|
|
|
|
formats.push_back(format);
|
2017-11-09 13:43:42 +01:00
|
|
|
for (const SdpVideoFormat& h264_format : SupportedH264Codecs())
|
|
|
|
|
formats.push_back(h264_format);
|
|
|
|
|
return formats;
|
|
|
|
|
}
|
2016-12-01 00:27:27 -08:00
|
|
|
|
2017-11-09 13:43:42 +01:00
|
|
|
std::unique_ptr<VideoDecoder> InternalDecoderFactory::CreateVideoDecoder(
|
|
|
|
|
const SdpVideoFormat& format) {
|
2018-08-06 10:10:51 +02:00
|
|
|
if (!IsFormatSupported(GetSupportedFormats(), format)) {
|
|
|
|
|
RTC_LOG(LS_ERROR) << "Trying to create decoder for unsupported format";
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-23 10:07:25 +02:00
|
|
|
if (absl::EqualsIgnoreCase(format.name, cricket::kVp8CodecName))
|
2017-11-13 14:10:02 +01:00
|
|
|
return VP8Decoder::Create();
|
2018-10-23 10:07:25 +02:00
|
|
|
if (absl::EqualsIgnoreCase(format.name, cricket::kVp9CodecName))
|
2017-11-13 14:10:02 +01:00
|
|
|
return VP9Decoder::Create();
|
2018-10-23 10:07:25 +02:00
|
|
|
if (absl::EqualsIgnoreCase(format.name, cricket::kH264CodecName))
|
2017-11-13 14:10:02 +01:00
|
|
|
return H264Decoder::Create();
|
2018-08-06 10:10:51 +02:00
|
|
|
|
|
|
|
|
RTC_NOTREACHED();
|
2017-11-09 13:43:42 +01:00
|
|
|
return nullptr;
|
2016-12-01 00:27:27 -08:00
|
|
|
}
|
|
|
|
|
|
2017-11-09 13:43:42 +01:00
|
|
|
} // namespace webrtc
|