Add interface class for bitstream parser.

Bug: webrtc:10439
Change-Id: I0decbbf4aa21a96db50f340f200ccf8adc9e8b53
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128760
Commit-Queue: Kári Helgason <kthelgason@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27237}
This commit is contained in:
Kári Tristan Helgason
2019-03-22 11:19:08 +01:00
committed by Commit Bot
parent 1ca30a7e41
commit b163359751
5 changed files with 73 additions and 12 deletions

View File

@ -52,6 +52,16 @@ rtc_source_set("video_codecs_api") {
]
}
rtc_source_set("bitstream_parser_api") {
visibility = [ "*" ]
sources = [
"bitstream_parser.h",
]
deps = [
"..:array_view",
]
}
rtc_static_library("builtin_video_decoder_factory") {
visibility = [ "*" ]
allow_poison = [

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2019 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.
*/
#ifndef API_VIDEO_CODECS_BITSTREAM_PARSER_H_
#define API_VIDEO_CODECS_BITSTREAM_PARSER_H_
#include <stddef.h>
#include <stdint.h>
#include "api/array_view.h"
namespace webrtc {
// This class is an interface for bitstream parsers.
class BitstreamParser {
public:
virtual ~BitstreamParser() = default;
// Parse an additional chunk of the bitstream.
virtual void ParseBitstream(rtc::ArrayView<const uint8_t> bitstream) = 0;
// Get the last extracted QP value from the parsed bitstream. If no QP
// value could be parsed, returns absl::nullopt.
virtual absl::optional<int> GetLastSliceQp() const = 0;
};
} // namespace webrtc
#endif // API_VIDEO_CODECS_BITSTREAM_PARSER_H_

View File

@ -47,6 +47,7 @@ rtc_static_library("common_video") {
"../api/video:video_bitrate_allocator",
"../api/video:video_frame",
"../api/video:video_frame_i420",
"../api/video_codecs:bitstream_parser_api",
"../media:rtc_h264_profile_id",
"../rtc_base",
"../rtc_base:checks",

View File

@ -18,9 +18,11 @@
#include "rtc_base/logging.h"
namespace {
const int kMaxAbsQpDeltaValue = 51;
const int kMinQpValue = 0;
const int kMaxQpValue = 51;
} // namespace
namespace webrtc {
@ -313,4 +315,15 @@ bool H264BitstreamParser::GetLastSliceQp(int* qp) const {
return true;
}
void H264BitstreamParser::ParseBitstream(
rtc::ArrayView<const uint8_t> bitstream) {
ParseBitstream(bitstream.data(), bitstream.size());
}
absl::optional<int> H264BitstreamParser::GetLastSliceQp() const {
int qp;
bool success = GetLastSliceQp(&qp);
return success ? absl::optional<int>(qp) : absl::nullopt;
}
} // namespace webrtc

View File

@ -14,6 +14,7 @@
#include <stdint.h>
#include "absl/types/optional.h"
#include "api/video_codecs/bitstream_parser.h"
#include "common_video/h264/pps_parser.h"
#include "common_video/h264/sps_parser.h"
@ -25,24 +26,25 @@ namespace webrtc {
// TODO(pbos): If/when this gets used on the receiver side CHECKs must be
// removed and gracefully abort as we have no control over receive-side
// bitstreams.
class H264BitstreamParser {
class H264BitstreamParser : public BitstreamParser {
public:
H264BitstreamParser();
~H264BitstreamParser() override;
// These are here for backwards-compatability for the time being.
void ParseBitstream(const uint8_t* bitstream, size_t length);
bool GetLastSliceQp(int* qp) const;
// New interface.
void ParseBitstream(rtc::ArrayView<const uint8_t> bitstream) override;
absl::optional<int> GetLastSliceQp() const override;
protected:
enum Result {
kOk,
kInvalidStream,
kUnsupportedStream,
};
H264BitstreamParser();
virtual ~H264BitstreamParser();
// Parse an additional chunk of H264 bitstream.
void ParseBitstream(const uint8_t* bitstream, size_t length);
// Get the last extracted QP value from the parsed bitstream.
bool GetLastSliceQp(int* qp) const;
protected:
void ParseSlice(const uint8_t* slice, size_t length);
Result ParseNonParameterSetNalu(const uint8_t* source,
size_t source_length,