blob: 4eb8aeea53dc4ba8cbcad03098e16bbfbffd15a3 [file] [log] [blame]
philipelc707ab72016-04-01 02:01:54 -07001/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/modules/video_coding/frame_object.h"
philipelc707ab72016-04-01 02:01:54 -070012#include "webrtc/modules/video_coding/packet_buffer.h"
13
14namespace webrtc {
15namespace video_coding {
16
philipela1059872016-05-09 11:41:48 +020017FrameObject::FrameObject()
18 : picture_id(0),
19 spatial_layer(0),
philipelbe7a9e52016-05-19 12:19:35 +020020 timestamp(0),
philipela1059872016-05-09 11:41:48 +020021 num_references(0),
22 inter_layer_predicted(false) {}
23
philipelc707ab72016-04-01 02:01:54 -070024RtpFrameObject::RtpFrameObject(PacketBuffer* packet_buffer,
philipel02447bc2016-05-13 06:01:03 -070025 uint16_t first_seq_num,
philipel5ceaaae2016-05-24 10:20:47 +020026 uint16_t last_seq_num,
27 size_t frame_size,
philipelb4d31082016-07-11 08:46:29 -070028 int times_nacked,
29 int64_t received_time)
philipelc707ab72016-04-01 02:01:54 -070030 : packet_buffer_(packet_buffer),
philipel02447bc2016-05-13 06:01:03 -070031 first_seq_num_(first_seq_num),
philipel5ceaaae2016-05-24 10:20:47 +020032 last_seq_num_(last_seq_num),
philipelb4d31082016-07-11 08:46:29 -070033 received_time_(received_time),
philipel5ceaaae2016-05-24 10:20:47 +020034 times_nacked_(times_nacked) {
philipel02447bc2016-05-13 06:01:03 -070035 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num);
36 if (packet) {
philipel36928452016-11-07 10:42:36 +010037 // RtpFrameObject members
38 frame_type_ = packet->frameType;
39 codec_type_ = packet->codec;
40
philipel552866c2016-07-04 16:18:55 +020041 // TODO(philipel): Remove when encoded image is replaced by FrameObject.
42 // VCMEncodedFrame members
43 CopyCodecSpecific(&packet->video_header);
44 _completeFrame = true;
45 _payloadType = packet->payloadType;
46 _timeStamp = packet->timestamp;
47 ntp_time_ms_ = packet->ntp_time_ms_;
philipel36928452016-11-07 10:42:36 +010048
49 // Since FFmpeg use an optimized bitstream reader that reads in chunks of
50 // 32/64 bits we have to add at least that much padding to the buffer
51 // to make sure the decoder doesn't read out of bounds.
52 // NOTE! EncodedImage::_size is the size of the buffer (think capacity of
53 // an std::vector) and EncodedImage::_length is the actual size of
54 // the bitstream (think size of an std::vector).
55 if (codec_type_ == kVideoCodecH264)
56 _size = frame_size + EncodedImage::kBufferPaddingBytesH264;
57 else
58 _size = frame_size;
59
60 _buffer = new uint8_t[_size];
philipel552866c2016-07-04 16:18:55 +020061 _length = frame_size;
62 _frameType = packet->frameType;
63 GetBitstream(_buffer);
64
philipel552866c2016-07-04 16:18:55 +020065 // FrameObject members
66 timestamp = packet->timestamp;
philipel02447bc2016-05-13 06:01:03 -070067 }
68}
philipelc707ab72016-04-01 02:01:54 -070069
70RtpFrameObject::~RtpFrameObject() {
71 packet_buffer_->ReturnFrame(this);
72}
73
philipelf4139332016-04-20 10:26:34 +020074uint16_t RtpFrameObject::first_seq_num() const {
philipel02447bc2016-05-13 06:01:03 -070075 return first_seq_num_;
philipelc707ab72016-04-01 02:01:54 -070076}
77
philipelf4139332016-04-20 10:26:34 +020078uint16_t RtpFrameObject::last_seq_num() const {
philipel02447bc2016-05-13 06:01:03 -070079 return last_seq_num_;
80}
81
philipel5ceaaae2016-05-24 10:20:47 +020082int RtpFrameObject::times_nacked() const {
83 return times_nacked_;
84}
85
philipel02447bc2016-05-13 06:01:03 -070086FrameType RtpFrameObject::frame_type() const {
87 return frame_type_;
88}
89
90VideoCodecType RtpFrameObject::codec_type() const {
91 return codec_type_;
philipelc707ab72016-04-01 02:01:54 -070092}
93
philipelc707ab72016-04-01 02:01:54 -070094bool RtpFrameObject::GetBitstream(uint8_t* destination) const {
95 return packet_buffer_->GetBitstream(*this, destination);
96}
97
philipelb4d31082016-07-11 08:46:29 -070098uint32_t RtpFrameObject::Timestamp() const {
99 return timestamp_;
100}
101
102int64_t RtpFrameObject::ReceivedTime() const {
103 return received_time_;
104}
105
106int64_t RtpFrameObject::RenderTime() const {
107 return _renderTimeMs;
108}
109
philipel88488282016-11-03 08:56:54 -0700110rtc::Optional<RTPVideoTypeHeader> RtpFrameObject::GetCodecHeader() const {
111 rtc::CritScope lock(&packet_buffer_->crit_);
philipel02447bc2016-05-13 06:01:03 -0700112 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num_);
113 if (!packet)
philipel88488282016-11-03 08:56:54 -0700114 return rtc::Optional<RTPVideoTypeHeader>();
115 return rtc::Optional<RTPVideoTypeHeader>(packet->video_header.codecHeader);
philipel02447bc2016-05-13 06:01:03 -0700116}
117
philipelc707ab72016-04-01 02:01:54 -0700118} // namespace video_coding
119} // namespace webrtc