philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | namespace webrtc { |
| 16 | namespace video_coding { |
| 17 | |
philipel | a105987 | 2016-05-09 11:41:48 +0200 | [diff] [blame] | 18 | FrameObject::FrameObject() |
| 19 | : picture_id(0), |
| 20 | spatial_layer(0), |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 21 | timestamp(0), |
philipel | a105987 | 2016-05-09 11:41:48 +0200 | [diff] [blame] | 22 | num_references(0), |
| 23 | inter_layer_predicted(false) {} |
| 24 | |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 25 | RtpFrameObject::RtpFrameObject(PacketBuffer* packet_buffer, |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 26 | uint16_t first_seq_num, |
philipel | 5ceaaae | 2016-05-24 10:20:47 +0200 | [diff] [blame] | 27 | uint16_t last_seq_num, |
| 28 | size_t frame_size, |
philipel | b4d3108 | 2016-07-11 08:46:29 -0700 | [diff] [blame] | 29 | int times_nacked, |
| 30 | int64_t received_time) |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 31 | : packet_buffer_(packet_buffer), |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 32 | first_seq_num_(first_seq_num), |
philipel | 5ceaaae | 2016-05-24 10:20:47 +0200 | [diff] [blame] | 33 | last_seq_num_(last_seq_num), |
philipel | b4d3108 | 2016-07-11 08:46:29 -0700 | [diff] [blame] | 34 | received_time_(received_time), |
philipel | 5ceaaae | 2016-05-24 10:20:47 +0200 | [diff] [blame] | 35 | times_nacked_(times_nacked) { |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 36 | VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num); |
| 37 | if (packet) { |
philipel | 552866c | 2016-07-04 16:18:55 +0200 | [diff] [blame] | 38 | // 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 |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 52 | frame_type_ = packet->frameType; |
| 53 | codec_type_ = packet->codec; |
philipel | 552866c | 2016-07-04 16:18:55 +0200 | [diff] [blame] | 54 | |
| 55 | // FrameObject members |
| 56 | timestamp = packet->timestamp; |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 57 | } |
| 58 | } |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 59 | |
| 60 | RtpFrameObject::~RtpFrameObject() { |
| 61 | packet_buffer_->ReturnFrame(this); |
| 62 | } |
| 63 | |
philipel | f413933 | 2016-04-20 10:26:34 +0200 | [diff] [blame] | 64 | uint16_t RtpFrameObject::first_seq_num() const { |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 65 | return first_seq_num_; |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 66 | } |
| 67 | |
philipel | f413933 | 2016-04-20 10:26:34 +0200 | [diff] [blame] | 68 | uint16_t RtpFrameObject::last_seq_num() const { |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 69 | return last_seq_num_; |
| 70 | } |
| 71 | |
philipel | 5ceaaae | 2016-05-24 10:20:47 +0200 | [diff] [blame] | 72 | int RtpFrameObject::times_nacked() const { |
| 73 | return times_nacked_; |
| 74 | } |
| 75 | |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 76 | FrameType RtpFrameObject::frame_type() const { |
| 77 | return frame_type_; |
| 78 | } |
| 79 | |
| 80 | VideoCodecType RtpFrameObject::codec_type() const { |
| 81 | return codec_type_; |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 82 | } |
| 83 | |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 84 | bool RtpFrameObject::GetBitstream(uint8_t* destination) const { |
| 85 | return packet_buffer_->GetBitstream(*this, destination); |
| 86 | } |
| 87 | |
philipel | b4d3108 | 2016-07-11 08:46:29 -0700 | [diff] [blame] | 88 | uint32_t RtpFrameObject::Timestamp() const { |
| 89 | return timestamp_; |
| 90 | } |
| 91 | |
| 92 | int64_t RtpFrameObject::ReceivedTime() const { |
| 93 | return received_time_; |
| 94 | } |
| 95 | |
| 96 | int64_t RtpFrameObject::RenderTime() const { |
| 97 | return _renderTimeMs; |
| 98 | } |
| 99 | |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 100 | RTPVideoTypeHeader* RtpFrameObject::GetCodecHeader() const { |
| 101 | VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num_); |
| 102 | if (!packet) |
| 103 | return nullptr; |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 104 | return &packet->video_header.codecHeader; |
philipel | 02447bc | 2016-05-13 06:01:03 -0700 | [diff] [blame] | 105 | } |
| 106 | |
philipel | c707ab7 | 2016-04-01 02:01:54 -0700 | [diff] [blame] | 107 | } // namespace video_coding |
| 108 | } // namespace webrtc |