Skip to content

Commit

Permalink
添加头文件
Browse files Browse the repository at this point in the history
  • Loading branch information
feixiao committed Aug 22, 2018
1 parent bb1a947 commit beec1f3
Show file tree
Hide file tree
Showing 523 changed files with 52,916 additions and 0 deletions.
133 changes: 133 additions & 0 deletions webrtc_example/inc/common_video/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Copyright (c) 2014 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.

import("../webrtc.gni")

config("common_video_config") {
include_dirs = [ "include" ]
}

rtc_static_library("common_video") {
visibility = [ "*" ]

sources = [
"bitrate_adjuster.cc",
"h264/h264_bitstream_parser.cc",
"h264/h264_bitstream_parser.h",
"h264/h264_common.cc",
"h264/h264_common.h",
"h264/pps_parser.cc",
"h264/pps_parser.h",
"h264/profile_level_id.h",
"h264/sps_parser.cc",
"h264/sps_parser.h",
"h264/sps_vui_rewriter.cc",
"h264/sps_vui_rewriter.h",
"i420_buffer_pool.cc",
"include/bitrate_adjuster.h",
"include/frame_callback.h",
"include/i420_buffer_pool.h",
"include/incoming_video_stream.h",
"include/video_bitrate_allocator.h",
"include/video_frame.h",
"include/video_frame_buffer.h",
"incoming_video_stream.cc",
"libyuv/include/webrtc_libyuv.h",
"libyuv/webrtc_libyuv.cc",
"video_frame.cc",
"video_frame_buffer.cc",
"video_render_frames.cc",
"video_render_frames.h",
]

include_dirs = [ "../modules/interface" ]

public_configs = [ ":common_video_config" ]

if (!build_with_chromium && is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}

deps = [
"..:webrtc_common",
"../:typedefs",
"../api:optional",
"../api:video_frame_api",
"../api:video_frame_api_i420",
"../media:rtc_h264_profile_id",
"../modules:module_api",
"../rtc_base:checks",
"../rtc_base:rtc_base",
"../rtc_base:rtc_task_queue",
"../system_wrappers",
"//third_party/libyuv",
]
}

if (rtc_include_tests) {
common_video_resources = [ "../resources/foreman_cif.yuv" ]

if (is_ios) {
bundle_data("common_video_unittests_bundle_data") {
testonly = true
sources = common_video_resources
outputs = [
"{{bundle_resources_dir}}/{{source_file_part}}",
]
}
}

rtc_test("common_video_unittests") {
testonly = true

sources = [
"bitrate_adjuster_unittest.cc",
"h264/h264_bitstream_parser_unittest.cc",
"h264/pps_parser_unittest.cc",
"h264/profile_level_id_unittest.cc",
"h264/sps_parser_unittest.cc",
"h264/sps_vui_rewriter_unittest.cc",
"i420_buffer_pool_unittest.cc",
"i420_video_frame_unittest.cc",
"libyuv/libyuv_unittest.cc",
]

# TODO(jschuh): Bug 1348: fix this warning.
configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]

if (!build_with_chromium && is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}

deps = [
":common_video",
"../api:video_frame_api",
"../api:video_frame_api_i420",
"../modules/video_capture:video_capture",
"../rtc_base:rtc_base",
"../rtc_base:rtc_base_approved",
"../system_wrappers:system_wrappers",
"../test:test_main",
"../test:video_test_common",
"//testing/gtest",
"//third_party/libyuv",
]

data = common_video_resources
if (is_android) {
deps += [ "//testing/android/native_test:native_test_support" ]
shard_timeout = 900
}

if (is_ios) {
deps += [ ":common_video_unittests_bundle_data" ]
}
}
}
7 changes: 7 additions & 0 deletions webrtc_example/inc/common_video/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include_rules = [
"+media/base",
"+system_wrappers",
# TODO(magjed): This is temporary, remove once external clients are updated.
"+sdk/objc",
"+third_party/libyuv",
]
8 changes: 8 additions & 0 deletions webrtc_example/inc/common_video/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
magjed@webrtc.org
marpan@webrtc.org
stefan@webrtc.org

# These are for the common case of adding or renaming files. If you're doing
# structural changes, please get a review from a reviewer in this file.
per-file *.gn=*
per-file *.gni=*
65 changes: 65 additions & 0 deletions webrtc_example/inc/common_video/h264/h264_bitstream_parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.
*/

#ifndef COMMON_VIDEO_H264_H264_BITSTREAM_PARSER_H_
#define COMMON_VIDEO_H264_H264_BITSTREAM_PARSER_H_
#include <stddef.h>
#include <stdint.h>

#include "api/optional.h"
#include "common_video/h264/pps_parser.h"
#include "common_video/h264/sps_parser.h"

namespace rtc {
class BitBufferWriter;
}

namespace webrtc {

// Stateful H264 bitstream parser (due to SPS/PPS). Used to parse out QP values
// from the bitstream.
// TODO(pbos): Unify with RTP SPS parsing and only use one H264 parser.
// 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 {
public:
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,
uint8_t nalu_type);

// SPS/PPS state, updated when parsing new SPS/PPS, used to parse slices.
rtc::Optional<SpsParser::SpsState> sps_;
rtc::Optional<PpsParser::PpsState> pps_;

// Last parsed slice QP.
rtc::Optional<int32_t> last_slice_qp_delta_;
};

} // namespace webrtc

#endif // COMMON_VIDEO_H264_H264_BITSTREAM_PARSER_H_
88 changes: 88 additions & 0 deletions webrtc_example/inc/common_video/h264/h264_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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.
*/

#ifndef COMMON_VIDEO_H264_H264_COMMON_H_
#define COMMON_VIDEO_H264_H264_COMMON_H_

#include <memory>
#include <vector>

#include "rtc_base/buffer.h"

namespace webrtc {

namespace H264 {
// The size of a full NALU start sequence {0 0 0 1}, used for the first NALU
// of an access unit, and for SPS and PPS blocks.
const size_t kNaluLongStartSequenceSize = 4;

// The size of a shortened NALU start sequence {0 0 1}, that may be used if
// not the first NALU of an access unit or an SPS or PPS block.
const size_t kNaluShortStartSequenceSize = 3;

// The size of the NALU type byte (1).
const size_t kNaluTypeSize = 1;

enum NaluType : uint8_t {
kSlice = 1,
kIdr = 5,
kSei = 6,
kSps = 7,
kPps = 8,
kAud = 9,
kEndOfSequence = 10,
kEndOfStream = 11,
kFiller = 12,
kStapA = 24,
kFuA = 28
};

enum SliceType : uint8_t { kP = 0, kB = 1, kI = 2, kSp = 3, kSi = 4 };

struct NaluIndex {
// Start index of NALU, including start sequence.
size_t start_offset;
// Start index of NALU payload, typically type header.
size_t payload_start_offset;
// Length of NALU payload, in bytes, counting from payload_start_offset.
size_t payload_size;
};

// Returns a vector of the NALU indices in the given buffer.
std::vector<NaluIndex> FindNaluIndices(const uint8_t* buffer,
size_t buffer_size);

// Get the NAL type from the header byte immediately following start sequence.
NaluType ParseNaluType(uint8_t data);

// Methods for parsing and writing RBSP. See section 7.4.1 of the H264 spec.
//
// The following sequences are illegal, and need to be escaped when encoding:
// 00 00 00 -> 00 00 03 00
// 00 00 01 -> 00 00 03 01
// 00 00 02 -> 00 00 03 02
// And things in the source that look like the emulation byte pattern (00 00 03)
// need to have an extra emulation byte added, so it's removed when decoding:
// 00 00 03 -> 00 00 03 03
//
// Decoding is simply a matter of finding any 00 00 03 sequence and removing
// the 03 emulation byte.

// Parse the given data and remove any emulation byte escaping.
std::vector<uint8_t> ParseRbsp(const uint8_t* data, size_t length);

// Write the given data to the destination buffer, inserting and emulation
// bytes in order to escape any data the could be interpreted as a start
// sequence.
void WriteRbsp(const uint8_t* bytes, size_t length, rtc::Buffer* destination);
} // namespace H264
} // namespace webrtc

#endif // COMMON_VIDEO_H264_H264_COMMON_H_
62 changes: 62 additions & 0 deletions webrtc_example/inc/common_video/h264/pps_parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.
*/

#ifndef COMMON_VIDEO_H264_PPS_PARSER_H_
#define COMMON_VIDEO_H264_PPS_PARSER_H_

#include "api/optional.h"

namespace rtc {
class BitBuffer;
}

namespace webrtc {

// A class for parsing out picture parameter set (PPS) data from a H264 NALU.
class PpsParser {
public:
// The parsed state of the PPS. Only some select values are stored.
// Add more as they are actually needed.
struct PpsState {
PpsState() = default;

bool bottom_field_pic_order_in_frame_present_flag = false;
bool weighted_pred_flag = false;
bool entropy_coding_mode_flag = false;
uint32_t weighted_bipred_idc = false;
uint32_t redundant_pic_cnt_present_flag = 0;
int pic_init_qp_minus26 = 0;
uint32_t id = 0;
uint32_t sps_id = 0;
};

// Unpack RBSP and parse PPS state from the supplied buffer.
static rtc::Optional<PpsState> ParsePps(const uint8_t* data, size_t length);

static bool ParsePpsIds(const uint8_t* data,
size_t length,
uint32_t* pps_id,
uint32_t* sps_id);

static rtc::Optional<uint32_t> ParsePpsIdFromSlice(const uint8_t* data,
size_t length);

protected:
// Parse the PPS state, for a bit buffer where RBSP decoding has already been
// performed.
static rtc::Optional<PpsState> ParseInternal(rtc::BitBuffer* bit_buffer);
static bool ParsePpsIdsInternal(rtc::BitBuffer* bit_buffer,
uint32_t* pps_id,
uint32_t* sps_id);
};

} // namespace webrtc

#endif // COMMON_VIDEO_H264_PPS_PARSER_H_
19 changes: 19 additions & 0 deletions webrtc_example/inc/common_video/h264/profile_level_id.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.
*/

#ifndef COMMON_VIDEO_H264_PROFILE_LEVEL_ID_H_
#define COMMON_VIDEO_H264_PROFILE_LEVEL_ID_H_

#include "media/base/h264_profile_level_id.h"

// TODO(zhihuang): Delete this file once dependent applications switch to
// including "webrtc/media/base/h264_profile_level_id.h" directly.

#endif // COMMON_VIDEO_H264_PROFILE_LEVEL_ID_H_
Loading

0 comments on commit beec1f3

Please sign in to comment.