blob: acfb25d28d3594e4a0d2047091f20c2238ff8a3a [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"
12#include "webrtc/base/criticalsection.h"
13#include "webrtc/modules/video_coding/packet_buffer.h"
14
15namespace webrtc {
16namespace video_coding {
17
philipela1059872016-05-09 11:41:48 +020018FrameObject::FrameObject()
19 : picture_id(0),
20 spatial_layer(0),
philipelbe7a9e52016-05-19 12:19:35 +020021 timestamp(0),
philipela1059872016-05-09 11:41:48 +020022 num_references(0),
23 inter_layer_predicted(false) {}
24
philipelc707ab72016-04-01 02:01:54 -070025RtpFrameObject::RtpFrameObject(PacketBuffer* packet_buffer,
philipel02447bc2016-05-13 06:01:03 -070026 uint16_t first_seq_num,
philipel5ceaaae2016-05-24 10:20:47 +020027 uint16_t last_seq_num,
28 size_t frame_size,
philipelb4d31082016-07-11 08:46:29 -070029 int times_nacked,
30 int64_t received_time)
philipelc707ab72016-04-01 02:01:54 -070031 : packet_buffer_(packet_buffer),
philipel02447bc2016-05-13 06:01:03 -070032 first_seq_num_(first_seq_num),
philipel5ceaaae2016-05-24 10:20:47 +020033 last_seq_num_(last_seq_num),
philipelb4d31082016-07-11 08:46:29 -070034 received_time_(received_time),
philipel5ceaaae2016-05-24 10:20:47 +020035 times_nacked_(times_nacked) {
philipel02447bc2016-05-13 06:01:03 -070036 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num);
37 if (packet) {
philipel552866c2016-07-04 16:18:55 +020038 // TODO(philipel): Remove when encoded image is replaced by FrameObject.
39 // VCMEncodedFrame members
40 CopyCodecSpecific(&packet->video_header);
41 _completeFrame = true;
42 _payloadType = packet->payloadType;
43 _timeStamp = packet->timestamp;
44 ntp_time_ms_ = packet->ntp_time_ms_;
45 _buffer = new uint8_t[frame_size]();
46 _size = frame_size;
47 _length = frame_size;
48 _frameType = packet->frameType;
49 GetBitstream(_buffer);
50
51 // RtpFrameObject members
philipel02447bc2016-05-13 06:01:03 -070052 frame_type_ = packet->frameType;
53 codec_type_ = packet->codec;
philipel552866c2016-07-04 16:18:55 +020054
55 // FrameObject members
56 timestamp = packet->timestamp;
philipel02447bc2016-05-13 06:01:03 -070057 }
58}
philipelc707ab72016-04-01 02:01:54 -070059
60RtpFrameObject::~RtpFrameObject() {
61 packet_buffer_->ReturnFrame(this);
62}
63
philipelf4139332016-04-20 10:26:34 +020064uint16_t RtpFrameObject::first_seq_num() const {
philipel02447bc2016-05-13 06:01:03 -070065 return first_seq_num_;
philipelc707ab72016-04-01 02:01:54 -070066}
67
philipelf4139332016-04-20 10:26:34 +020068uint16_t RtpFrameObject::last_seq_num() const {
philipel02447bc2016-05-13 06:01:03 -070069 return last_seq_num_;
70}
71
philipel5ceaaae2016-05-24 10:20:47 +020072int RtpFrameObject::times_nacked() const {
73 return times_nacked_;
74}
75
philipel02447bc2016-05-13 06:01:03 -070076FrameType RtpFrameObject::frame_type() const {
77 return frame_type_;
78}
79
80VideoCodecType RtpFrameObject::codec_type() const {
81 return codec_type_;
philipelc707ab72016-04-01 02:01:54 -070082}
83
philipelc707ab72016-04-01 02:01:54 -070084bool RtpFrameObject::GetBitstream(uint8_t* destination) const {
85 return packet_buffer_->GetBitstream(*this, destination);
86}
87
philipelb4d31082016-07-11 08:46:29 -070088uint32_t RtpFrameObject::Timestamp() const {
89 return timestamp_;
90}
91
92int64_t RtpFrameObject::ReceivedTime() const {
93 return received_time_;
94}
95
96int64_t RtpFrameObject::RenderTime() const {
97 return _renderTimeMs;
98}
99
philipel02447bc2016-05-13 06:01:03 -0700100RTPVideoTypeHeader* RtpFrameObject::GetCodecHeader() const {
101 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num_);
102 if (!packet)
103 return nullptr;
isheriff6b4b5f32016-06-08 00:24:21 -0700104 return &packet->video_header.codecHeader;
philipel02447bc2016-05-13 06:01:03 -0700105}
106
philipelc707ab72016-04-01 02:01:54 -0700107} // namespace video_coding
108} // namespace webrtc