Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(736)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_format_vp9.cc

Issue 2522553002: RtpPacketizer::NextPacket fills RtpPacket instead of payload. (Closed)
Patch Set: Named kTheMagicSix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp9.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp9.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <string.h> 14 #include <string.h>
15 15
16 #include <cmath> 16 #include <cmath>
17 17
18 #include "webrtc/base/bitbuffer.h" 18 #include "webrtc/base/bitbuffer.h"
19 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
20 #include "webrtc/base/logging.h" 20 #include "webrtc/base/logging.h"
21 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h"
21 22
22 #define RETURN_FALSE_ON_ERROR(x) \ 23 #define RETURN_FALSE_ON_ERROR(x) \
23 if (!(x)) { \ 24 if (!(x)) { \
24 return false; \ 25 return false; \
25 } 26 }
26 27
27 namespace webrtc { 28 namespace webrtc {
28 namespace { 29 namespace {
29 // Length of VP9 payload descriptors' fixed part. 30 // Length of VP9 payload descriptors' fixed part.
30 const size_t kFixedPayloadDescriptorBytes = 1; 31 const size_t kFixedPayloadDescriptorBytes = 1;
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 packets_.pop(); 539 packets_.pop();
539 return; 540 return;
540 } 541 }
541 QueuePacket(bytes_processed, packet_bytes, bytes_processed == 0, 542 QueuePacket(bytes_processed, packet_bytes, bytes_processed == 0,
542 rem_bytes == packet_bytes, &packets_); 543 rem_bytes == packet_bytes, &packets_);
543 bytes_processed += packet_bytes; 544 bytes_processed += packet_bytes;
544 } 545 }
545 assert(bytes_processed == payload_size_); 546 assert(bytes_processed == payload_size_);
546 } 547 }
547 548
548 bool RtpPacketizerVp9::NextPacket(uint8_t* buffer, 549 bool RtpPacketizerVp9::NextPacket(RtpPacketToSend* packet, bool* last_packet) {
549 size_t* bytes_to_send, 550 RTC_DCHECK(packet);
550 bool* last_packet) { 551 RTC_DCHECK(last_packet);
551 if (packets_.empty()) { 552 if (packets_.empty()) {
552 return false; 553 return false;
553 } 554 }
554 PacketInfo packet_info = packets_.front(); 555 PacketInfo packet_info = packets_.front();
555 packets_.pop(); 556 packets_.pop();
556 557
557 if (!WriteHeaderAndPayload(packet_info, buffer, bytes_to_send)) { 558 if (!WriteHeaderAndPayload(packet_info, packet)) {
558 return false; 559 return false;
559 } 560 }
560 *last_packet = 561 *last_packet = packets_.empty();
561 packets_.empty() && (hdr_.spatial_idx == kNoSpatialIdx || 562 packet->SetMarker(packets_.empty() &&
562 hdr_.spatial_idx == hdr_.num_spatial_layers - 1); 563 (hdr_.spatial_idx == kNoSpatialIdx ||
564 hdr_.spatial_idx == hdr_.num_spatial_layers - 1));
563 return true; 565 return true;
564 } 566 }
565 567
566 // VP9 format: 568 // VP9 format:
567 // 569 //
568 // Payload descriptor for F = 1 (flexible mode) 570 // Payload descriptor for F = 1 (flexible mode)
569 // 0 1 2 3 4 5 6 7 571 // 0 1 2 3 4 5 6 7
570 // +-+-+-+-+-+-+-+-+ 572 // +-+-+-+-+-+-+-+-+
571 // |I|P|L|F|B|E|V|-| (REQUIRED) 573 // |I|P|L|F|B|E|V|-| (REQUIRED)
572 // +-+-+-+-+-+-+-+-+ 574 // +-+-+-+-+-+-+-+-+
(...skipping 20 matching lines...) Expand all
593 // +-+-+-+-+-+-+-+-+ 595 // +-+-+-+-+-+-+-+-+
594 // L: | T |U| S |D| (CONDITIONALLY RECOMMENDED) 596 // L: | T |U| S |D| (CONDITIONALLY RECOMMENDED)
595 // +-+-+-+-+-+-+-+-+ 597 // +-+-+-+-+-+-+-+-+
596 // | TL0PICIDX | (CONDITIONALLY REQUIRED) 598 // | TL0PICIDX | (CONDITIONALLY REQUIRED)
597 // +-+-+-+-+-+-+-+-+ 599 // +-+-+-+-+-+-+-+-+
598 // V: | SS | 600 // V: | SS |
599 // | .. | 601 // | .. |
600 // +-+-+-+-+-+-+-+-+ 602 // +-+-+-+-+-+-+-+-+
601 603
602 bool RtpPacketizerVp9::WriteHeaderAndPayload(const PacketInfo& packet_info, 604 bool RtpPacketizerVp9::WriteHeaderAndPayload(const PacketInfo& packet_info,
603 uint8_t* buffer, 605 RtpPacketToSend* packet) const {
604 size_t* bytes_to_send) const { 606 uint8_t* buffer = packet->AllocatePayload(max_payload_length_);
607 RTC_DCHECK(buffer);
605 size_t header_length; 608 size_t header_length;
606 if (!WriteHeader(packet_info, buffer, &header_length)) 609 if (!WriteHeader(packet_info, buffer, &header_length))
607 return false; 610 return false;
608 611
609 // Copy payload data. 612 // Copy payload data.
610 memcpy(&buffer[header_length], 613 memcpy(&buffer[header_length],
611 &payload_[packet_info.payload_start_pos], packet_info.size); 614 &payload_[packet_info.payload_start_pos], packet_info.size);
612 615
613 *bytes_to_send = header_length + packet_info.size; 616 packet->SetPayloadSize(header_length + packet_info.size);
614 return true; 617 return true;
615 } 618 }
616 619
617 bool RtpPacketizerVp9::WriteHeader(const PacketInfo& packet_info, 620 bool RtpPacketizerVp9::WriteHeader(const PacketInfo& packet_info,
618 uint8_t* buffer, 621 uint8_t* buffer,
619 size_t* header_length) const { 622 size_t* header_length) const {
620 // Required payload descriptor byte. 623 // Required payload descriptor byte.
621 bool i_bit = PictureIdPresent(hdr_); 624 bool i_bit = PictureIdPresent(hdr_);
622 bool p_bit = hdr_.inter_pic_predicted; 625 bool p_bit = hdr_.inter_pic_predicted;
623 bool l_bit = LayerInfoPresent(hdr_); 626 bool l_bit = LayerInfoPresent(hdr_);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 if (parsed_payload->payload_length == 0) { 737 if (parsed_payload->payload_length == 0) {
735 LOG(LS_ERROR) << "Failed parsing VP9 payload data."; 738 LOG(LS_ERROR) << "Failed parsing VP9 payload data.";
736 return false; 739 return false;
737 } 740 }
738 parsed_payload->payload = 741 parsed_payload->payload =
739 payload + payload_length - parsed_payload->payload_length; 742 payload + payload_length - parsed_payload->payload_length;
740 743
741 return true; 744 return true;
742 } 745 }
743 } // namespace webrtc 746 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_format_vp9.h ('k') | webrtc/modules/rtp_rtcp/source/rtp_format_vp9_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698