OLD | NEW |
---|---|
(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 | |
16 #include "webrtc/base/checks.h" | |
17 #include "webrtc/modules/audio_coding/neteq/tools/packet.h" | |
18 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" | |
19 #include "webrtc/video/rtc_event_log.h" | |
20 | |
21 // Files generated at build-time by the protobuf compiler. | |
22 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | |
23 #include "external/webrtc/webrtc/video/rtc_event_log.pb.h" | |
24 #else | |
25 #include "webrtc/video/rtc_event_log.pb.h" | |
26 #endif | |
27 | |
28 namespace webrtc { | |
29 namespace test { | |
30 | |
31 RtcEventLogSource* RtcEventLogSource::Create(const std::string& file_name) { | |
32 RtcEventLogSource* source = new RtcEventLogSource(); | |
33 CHECK(source->OpenFile(file_name)); | |
34 return source; | |
35 } | |
36 | |
37 RtcEventLogSource::~RtcEventLogSource() { | |
38 } | |
39 | |
40 bool RtcEventLogSource::RegisterRtpHeaderExtension(RTPExtensionType type, | |
41 uint8_t id) { | |
42 assert(parser_.get()); | |
hlundin-webrtc
2015/08/28 12:06:25
CHECK instead. This is test/tools code; better to
ivoc
2015/09/01 10:03:50
Done.
| |
43 return parser_->RegisterRtpHeaderExtension(type, id); | |
44 } | |
45 | |
46 Packet* RtcEventLogSource::NextPacket() { | |
47 for (; rtp_packet_index_ < event_log_->stream_size(); rtp_packet_index_++) { | |
48 const rtclog::Event& event = event_log_->stream(rtp_packet_index_); | |
49 if (event.has_type() && event.type() == rtclog::Event::RTP_EVENT) { | |
hlundin-webrtc
2015/08/28 12:06:25
This is a very long harangue of nested if statemen
ivoc
2015/09/01 10:03:50
Great idea, I refactored the code like you suggest
| |
50 if (event.has_timestamp_us() && event.has_rtp_packet()) { | |
51 const rtclog::RtpPacket& rtp_packet = event.rtp_packet(); | |
52 if (rtp_packet.has_type() && rtp_packet.type() == rtclog::AUDIO && | |
53 rtp_packet.has_incoming() && rtp_packet.incoming() == true && | |
hlundin-webrtc
2015/08/28 12:06:25
You can omit "== true".
ivoc
2015/09/01 10:03:50
Done.
| |
54 rtp_packet.has_packet_length() && rtp_packet.packet_length() > 0 && | |
55 rtp_packet.has_header() && rtp_packet.header().size() > 0 && | |
56 rtp_packet.packet_length() >= rtp_packet.header().size()) { | |
57 // Increase the index to avoid rechecking this event the next time | |
58 // the function is called. | |
59 rtp_packet_index_++; | |
hlundin-webrtc
2015/08/28 12:06:25
The double increment (in the for statement and her
ivoc
2015/09/01 10:03:50
Done.
| |
60 uint8_t* packet_data = new uint8_t[rtp_packet.header().size()]; | |
61 memcpy(packet_data, rtp_packet.header().data(), | |
minyue-webrtc
2015/08/28 16:54:17
Do you need payload data for packet_data, and is r
ivoc
2015/09/01 10:03:50
Right now the rtp packet message in the protobuf o
minyue-webrtc
2015/09/01 11:48:35
Yes, that makes it clearer.
Now I see why I had a
| |
62 rtp_packet.header().size()); | |
63 rtc::scoped_ptr<Packet> packet( | |
minyue-webrtc
2015/08/28 14:50:21
what is the life time of packet?
I'd like the met
ivoc
2015/09/01 10:03:50
I agree that this is not super obvious, but the re
minyue-webrtc
2015/09/01 11:48:35
No bother. maybe no need of scoped_ptr around pack
| |
64 new Packet(packet_data, rtp_packet.header().size(), | |
65 rtp_packet.packet_length(), | |
66 event.timestamp_us() / 1000, *parser_.get())); | |
67 if (!packet->valid_header()) { | |
hlundin-webrtc
2015/08/28 12:06:25
Are we expecting the logger to write invalid heade
ivoc
2015/09/01 10:03:50
The header is currently not checked while writing,
| |
68 assert(false); | |
69 return nullptr; | |
70 } | |
71 if (filter_.test(packet->header().payloadType) || | |
72 (use_ssrc_filter_ && packet->header().ssrc != ssrc_)) { | |
73 // This payload type should be filtered out. Continue to the next | |
hlundin-webrtc
2015/08/28 12:06:25
s/payload type/packet/
ivoc
2015/09/01 10:03:50
I replaced this, but I also restructured this code
| |
74 // packet. | |
75 continue; | |
76 } | |
77 return packet.release(); | |
78 } | |
79 } | |
80 } | |
81 } | |
82 return nullptr; | |
83 } | |
84 | |
85 int RtcEventLogSource::NextAudioOutputEventMs() { | |
86 for (; audio_output_index_ < event_log_->stream_size(); | |
87 audio_output_index_++) { | |
88 const rtclog::Event& event = event_log_->stream(audio_output_index_); | |
89 if (event.has_type() && event.type() == rtclog::Event::DEBUG_EVENT) { | |
hlundin-webrtc
2015/08/28 12:06:25
Same comment as above about a helper function.
ivoc
2015/09/01 10:03:50
I restructured in a similar way.
| |
90 if (event.has_timestamp_us() && event.has_debug_event()) { | |
91 const rtclog::DebugEvent& debug_event = event.debug_event(); | |
92 if (debug_event.has_type() && | |
93 debug_event.type() == rtclog::DebugEvent::AUDIO_PLAYOUT) { | |
94 // Increase the index to avoid rechecking this event the next time | |
95 // the function is called. | |
96 audio_output_index_++; | |
hlundin-webrtc
2015/08/28 12:06:25
Same awkwardness here.
ivoc
2015/09/01 10:03:50
Same fix applied.
| |
97 return event.timestamp_us() / 1000; | |
hlundin-webrtc
2015/08/28 12:06:25
What is the type of timestamp_us? If it is not int
ivoc
2015/09/01 10:03:50
The value is int64_t, so I changed the return type
| |
98 } | |
99 } | |
100 } | |
101 } | |
102 return -1; | |
103 } | |
104 | |
105 RtcEventLogSource::RtcEventLogSource() | |
106 : PacketSource(), parser_(RtpHeaderParser::Create()) { | |
107 } | |
108 | |
109 bool RtcEventLogSource::OpenFile(const std::string& file_name) { | |
110 event_log_.reset(new rtclog::EventStream()); | |
111 return RtcEventLog::ParseRtcEventLog(file_name, event_log_.get()); | |
112 } | |
113 | |
114 } // namespace test | |
115 } // namespace webrtc | |
OLD | NEW |