blob: fe3b2b02951aec241173e80aebe791f1e0a8d11a [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) {
36 size = frame_size;
philipel02447bc2016-05-13 06:01:03 -070037 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num);
38 if (packet) {
philipel552866c2016-07-04 16:18:55 +020039 // TODO(philipel): Remove when encoded image is replaced by FrameObject.
40 // VCMEncodedFrame members
41 CopyCodecSpecific(&packet->video_header);
42 _completeFrame = true;
43 _payloadType = packet->payloadType;
44 _timeStamp = packet->timestamp;
45 ntp_time_ms_ = packet->ntp_time_ms_;
46 _buffer = new uint8_t[frame_size]();
47 _size = frame_size;
48 _length = frame_size;
49 _frameType = packet->frameType;
50 GetBitstream(_buffer);
51
52 // RtpFrameObject members
philipel02447bc2016-05-13 06:01:03 -070053 frame_type_ = packet->frameType;
54 codec_type_ = packet->codec;
philipel552866c2016-07-04 16:18:55 +020055
56 // FrameObject members
57 timestamp = packet->timestamp;
philipel02447bc2016-05-13 06:01:03 -070058 }
59}
philipelc707ab72016-04-01 02:01:54 -070060
61RtpFrameObject::~RtpFrameObject() {
62 packet_buffer_->ReturnFrame(this);
63}
64
philipelf4139332016-04-20 10:26:34 +020065uint16_t RtpFrameObject::first_seq_num() const {
philipel02447bc2016-05-13 06:01:03 -070066 return first_seq_num_;
philipelc707ab72016-04-01 02:01:54 -070067}
68
philipelf4139332016-04-20 10:26:34 +020069uint16_t RtpFrameObject::last_seq_num() const {
philipel02447bc2016-05-13 06:01:03 -070070 return last_seq_num_;
71}
72
philipel5ceaaae2016-05-24 10:20:47 +020073int RtpFrameObject::times_nacked() const {
74 return times_nacked_;
75}
76
philipel02447bc2016-05-13 06:01:03 -070077FrameType RtpFrameObject::frame_type() const {
78 return frame_type_;
79}
80
81VideoCodecType RtpFrameObject::codec_type() const {
82 return codec_type_;
philipelc707ab72016-04-01 02:01:54 -070083}
84
philipelc707ab72016-04-01 02:01:54 -070085bool RtpFrameObject::GetBitstream(uint8_t* destination) const {
86 return packet_buffer_->GetBitstream(*this, destination);
87}
88
philipelb4d31082016-07-11 08:46:29 -070089uint32_t RtpFrameObject::Timestamp() const {
90 return timestamp_;
91}
92
93int64_t RtpFrameObject::ReceivedTime() const {
94 return received_time_;
95}
96
97int64_t RtpFrameObject::RenderTime() const {
98 return _renderTimeMs;
99}
100
philipel02447bc2016-05-13 06:01:03 -0700101RTPVideoTypeHeader* RtpFrameObject::GetCodecHeader() const {
102 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num_);
103 if (!packet)
104 return nullptr;
isheriff6b4b5f32016-06-08 00:24:21 -0700105 return &packet->video_header.codecHeader;
philipel02447bc2016-05-13 06:01:03 -0700106}
107
philipelc707ab72016-04-01 02:01:54 -0700108} // namespace video_coding
109} // namespace webrtc