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

Side by Side Diff: webrtc/modules/audio_coding/neteq/tools/rtc_event_log_source.cc

Issue 1316903002: Update to the neteq_rtpplay utility to support RtcEventLog input files. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Replaced filetype detection code, and various small improvements. Created 5 years, 3 months 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
(Empty)
1 /*
2 * Copyright (c) 2015 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/audio_coding/neteq/tools/rtc_event_log_source.h"
12
13 #include <assert.h>
14 #include <string.h>
15 #include <iostream>
16 #include <limits>
17
18 #include "webrtc/base/checks.h"
19 #include "webrtc/modules/audio_coding/neteq/tools/packet.h"
20 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
21 #include "webrtc/video/rtc_event_log.h"
22
23 // Files generated at build-time by the protobuf compiler.
24 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
25 #include "external/webrtc/webrtc/video/rtc_event_log.pb.h"
26 #else
27 #include "webrtc/video/rtc_event_log.pb.h"
28 #endif
29
30 namespace webrtc {
31 namespace test {
32
33 namespace {
34
35 const rtclog::RtpPacket* GetRtpPacket(const rtclog::Event& event) {
36 if (!event.has_type() || event.type() != rtclog::Event::RTP_EVENT)
37 return nullptr;
38 if (!event.has_timestamp_us() || !event.has_rtp_packet())
39 return nullptr;
40 const rtclog::RtpPacket& rtp_packet = event.rtp_packet();
41 if (!rtp_packet.has_type() || rtp_packet.type() != rtclog::AUDIO ||
42 !rtp_packet.has_incoming() || !rtp_packet.incoming() ||
43 !rtp_packet.has_packet_length() || rtp_packet.packet_length() == 0 ||
44 !rtp_packet.has_header() || rtp_packet.header().size() == 0 ||
45 rtp_packet.packet_length() < rtp_packet.header().size())
46 return nullptr;
47 return &rtp_packet;
48 }
49
50 const rtclog::DebugEvent* GetAudioOutputEvent(const rtclog::Event& event) {
51 if (!event.has_type() || event.type() != rtclog::Event::DEBUG_EVENT)
52 return nullptr;
53 if (!event.has_timestamp_us() || !event.has_debug_event())
54 return nullptr;
55 const rtclog::DebugEvent& debug_event = event.debug_event();
56 if (!debug_event.has_type() ||
57 debug_event.type() != rtclog::DebugEvent::AUDIO_PLAYOUT)
58 return nullptr;
59 return &debug_event;
60 }
61
62 } // namespace
63
64 RtcEventLogSource* RtcEventLogSource::Create(const std::string& file_name) {
65 RtcEventLogSource* source = new RtcEventLogSource();
66 CHECK(source->OpenFile(file_name));
67 return source;
68 }
69
70 RtcEventLogSource::~RtcEventLogSource() {
71 }
72
73 bool RtcEventLogSource::RegisterRtpHeaderExtension(RTPExtensionType type,
74 uint8_t id) {
75 CHECK(parser_.get());
76 return parser_->RegisterRtpHeaderExtension(type, id);
77 }
78
79 Packet* RtcEventLogSource::NextPacket() {
80 while (rtp_packet_index_ < event_log_->stream_size()) {
81 const rtclog::Event& event = event_log_->stream(rtp_packet_index_);
82 const rtclog::RtpPacket* rtp_packet = GetRtpPacket(event);
83 rtp_packet_index_++;
84 if (rtp_packet) {
85 uint8_t* packet_header = new uint8_t[rtp_packet->header().size()];
86 memcpy(packet_header, rtp_packet->header().data(),
87 rtp_packet->header().size());
88 Packet* packet =
89 new Packet(packet_header, rtp_packet->header().size(),
90 rtp_packet->packet_length(), event.timestamp_us() / 1000,
91 *parser_.get());
92 if (packet->valid_header()) {
93 // Check if the packet should not be filtered out.
94 if (!filter_.test(packet->header().payloadType) &&
95 !(use_ssrc_filter_ && packet->header().ssrc != ssrc_))
96 return packet;
97 } else {
98 std::cout << "Warning: Packet with index " << (rtp_packet_index_ - 1)
99 << " has an invalid header and will be ignored." << std::endl;
100 }
101 // The packet has either an invalid header or needs to be filtered out, so
102 // it can be deleted.
103 delete packet;
104 }
105 }
106 return nullptr;
107 }
108
109 int64_t RtcEventLogSource::NextAudioOutputEventMs() {
110 while (audio_output_index_ < event_log_->stream_size()) {
111 const rtclog::Event& event = event_log_->stream(audio_output_index_);
112 const rtclog::DebugEvent* debug_event = GetAudioOutputEvent(event);
113 audio_output_index_++;
114 if (debug_event)
115 return event.timestamp_us() / 1000;
116 }
117 return std::numeric_limits<int64_t>::max();
118 }
119
120 RtcEventLogSource::RtcEventLogSource()
121 : PacketSource(), parser_(RtpHeaderParser::Create()) {
122 }
123
124 bool RtcEventLogSource::OpenFile(const std::string& file_name) {
125 event_log_.reset(new rtclog::EventStream());
126 return RtcEventLog::ParseRtcEventLog(file_name, event_log_.get());
127 }
128
129 } // namespace test
130 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698