diff options
author | miu <miu@chromium.org> | 2015-11-03 17:21:08 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-04 01:22:06 +0000 |
commit | 54f315729b0f82a60e4600a6fcfce385cdae3e2b (patch) | |
tree | 38cb450c6bf2d07fbf9d162d533c620e22051498 /media/cast/logging | |
parent | 3fe2a2afc6451206d67de51707d77366acf98ed9 (diff) | |
download | chromium_src-54f315729b0f82a60e4600a6fcfce385cdae3e2b.zip chromium_src-54f315729b0f82a60e4600a6fcfce385cdae3e2b.tar.gz chromium_src-54f315729b0f82a60e4600a6fcfce385cdae3e2b.tar.bz2 |
Reland: [Cast] Thread-safe LogEventDispatcher for packet/frame event logging.
This is a reland of
https://crrev.com/00b4e5f928016ad89286843b3b92c2dec35c78ac with a minor
function signature change in cast_benchmarks.cc. This was not caught in
the original change because this file is only built as part of a
non-chrome executable target.
BUG=530841
TBR=imcheng@chromium.org
Review URL: https://codereview.chromium.org/1410353011
Cr-Commit-Position: refs/heads/master@{#357704}
Diffstat (limited to 'media/cast/logging')
-rw-r--r-- | media/cast/logging/encoding_event_subscriber_unittest.cc | 423 | ||||
-rw-r--r-- | media/cast/logging/log_event_dispatcher.cc | 137 | ||||
-rw-r--r-- | media/cast/logging/log_event_dispatcher.h | 81 | ||||
-rw-r--r-- | media/cast/logging/logging_impl.cc | 131 | ||||
-rw-r--r-- | media/cast/logging/logging_impl.h | 86 | ||||
-rw-r--r-- | media/cast/logging/logging_impl_unittest.cc | 235 | ||||
-rw-r--r-- | media/cast/logging/logging_raw.cc | 140 | ||||
-rw-r--r-- | media/cast/logging/logging_raw.h | 106 | ||||
-rw-r--r-- | media/cast/logging/logging_raw_unittest.cc | 202 | ||||
-rw-r--r-- | media/cast/logging/raw_event_subscriber_bundle.cc | 20 | ||||
-rw-r--r-- | media/cast/logging/receiver_time_offset_estimator_impl_unittest.cc | 386 | ||||
-rw-r--r-- | media/cast/logging/simple_event_subscriber_unittest.cc | 80 | ||||
-rw-r--r-- | media/cast/logging/stats_event_subscriber_unittest.cc | 362 |
13 files changed, 965 insertions, 1424 deletions
diff --git a/media/cast/logging/encoding_event_subscriber_unittest.cc b/media/cast/logging/encoding_event_subscriber_unittest.cc index b052bbb..123a8fe 100644 --- a/media/cast/logging/encoding_event_subscriber_unittest.cc +++ b/media/cast/logging/encoding_event_subscriber_unittest.cc @@ -43,15 +43,12 @@ class EncodingEventSubscriberTest : public ::testing::Test { void Init(EventMediaType event_media_type) { DCHECK(!event_subscriber_); event_subscriber_.reset(new EncodingEventSubscriber(event_media_type, 10)); - cast_environment_->Logging()->AddRawEventSubscriber( - event_subscriber_.get()); + cast_environment_->logger()->Subscribe(event_subscriber_.get()); } ~EncodingEventSubscriberTest() override { - if (event_subscriber_) { - cast_environment_->Logging()->RemoveRawEventSubscriber( - event_subscriber_.get()); - } + if (event_subscriber_) + cast_environment_->logger()->Unsubscribe(event_subscriber_.get()); } void GetEventsAndReset() { @@ -79,20 +76,30 @@ TEST_F(EncodingEventSubscriberTest, FrameEventTruncating) { int width = 320; int height = 180; for (int i = 0; i < 11; i++) { - cast_environment_->Logging()->InsertFrameEvent(now, - FRAME_CAPTURE_BEGIN, - VIDEO_EVENT, - i * 100, - /*frame_id*/ 0); - cast_environment_->Logging()->InsertCapturedVideoFrameEvent(now, - i * 100, - width, - height); - cast_environment_->Logging()->InsertFrameEvent(now, - FRAME_DECODED, - VIDEO_EVENT, - i * 100, - /*frame_id*/ 0); + scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent()); + capture_begin_event->timestamp = now; + capture_begin_event->type = FRAME_CAPTURE_BEGIN; + capture_begin_event->media_type = VIDEO_EVENT; + capture_begin_event->rtp_timestamp = i * 100; + cast_environment_->logger()->DispatchFrameEvent(capture_begin_event.Pass()); + + scoped_ptr<FrameEvent> capture_end_event(new FrameEvent()); + capture_end_event->timestamp = now; + capture_end_event->type = FRAME_CAPTURE_END; + capture_end_event->media_type = VIDEO_EVENT; + capture_end_event->rtp_timestamp = i * 100; + capture_end_event->width = width; + capture_end_event->height = height; + cast_environment_->logger()->DispatchFrameEvent(capture_end_event.Pass()); + + scoped_ptr<FrameEvent> decoded_event(new FrameEvent()); + decoded_event->timestamp = now; + decoded_event->type = FRAME_DECODED; + decoded_event->media_type = VIDEO_EVENT; + decoded_event->rtp_timestamp = i * 100; + decoded_event->frame_id = 0; + cast_environment_->logger()->DispatchFrameEvent(decoded_event.Pass()); + width += 160; height += 90; } @@ -119,14 +126,16 @@ TEST_F(EncodingEventSubscriberTest, PacketEventTruncating) { // Entry with RTP timestamp 0 should get dropped. for (int i = 0; i < 11; i++) { - cast_environment_->Logging()->InsertPacketEvent(now, - PACKET_RECEIVED, - AUDIO_EVENT, - /*rtp_timestamp*/ i * 100, - /*frame_id*/ 0, - /*packet_id*/ i, - /*max_packet_id*/ 10, - /*size*/ 123); + scoped_ptr<PacketEvent> receive_event(new PacketEvent()); + receive_event->timestamp = now; + receive_event->type = PACKET_RECEIVED; + receive_event->media_type = AUDIO_EVENT; + receive_event->rtp_timestamp = i * 100; + receive_event->frame_id = 0; + receive_event->packet_id = i; + receive_event->max_packet_id = 10; + receive_event->size = 123; + cast_environment_->logger()->DispatchPacketEvent(receive_event.Pass()); } GetEventsAndReset(); @@ -141,18 +150,22 @@ TEST_F(EncodingEventSubscriberTest, EventFiltering) { base::TimeTicks now(testing_clock_->NowTicks()); RtpTimestamp rtp_timestamp = 100; - cast_environment_->Logging()->InsertFrameEvent(now, - FRAME_DECODED, - VIDEO_EVENT, - rtp_timestamp, - /*frame_id*/ 0); + scoped_ptr<FrameEvent> video_event(new FrameEvent()); + video_event->timestamp = now; + video_event->type = FRAME_DECODED; + video_event->media_type = VIDEO_EVENT; + video_event->rtp_timestamp = rtp_timestamp; + video_event->frame_id = 0; + cast_environment_->logger()->DispatchFrameEvent(video_event.Pass()); // This is an AUDIO_EVENT and shouldn't be processed by the subscriber. - cast_environment_->Logging()->InsertFrameEvent(now, - FRAME_DECODED, - AUDIO_EVENT, - rtp_timestamp, - /*frame_id*/ 0); + scoped_ptr<FrameEvent> audio_event(new FrameEvent()); + audio_event->timestamp = now; + audio_event->type = FRAME_DECODED; + audio_event->media_type = AUDIO_EVENT; + audio_event->rtp_timestamp = rtp_timestamp; + audio_event->frame_id = 0; + cast_environment_->logger()->DispatchFrameEvent(audio_event.Pass()); GetEventsAndReset(); @@ -174,10 +187,13 @@ TEST_F(EncodingEventSubscriberTest, FrameEvent) { Init(VIDEO_EVENT); base::TimeTicks now(testing_clock_->NowTicks()); RtpTimestamp rtp_timestamp = 100; - cast_environment_->Logging()->InsertFrameEvent(now, FRAME_DECODED, - VIDEO_EVENT, - rtp_timestamp, - /*frame_id*/ 0); + scoped_ptr<FrameEvent> decode_event(new FrameEvent()); + decode_event->timestamp = now; + decode_event->type = FRAME_DECODED; + decode_event->media_type = VIDEO_EVENT; + decode_event->rtp_timestamp = rtp_timestamp; + decode_event->frame_id = 0; + cast_environment_->logger()->DispatchFrameEvent(decode_event.Pass()); GetEventsAndReset(); @@ -207,9 +223,14 @@ TEST_F(EncodingEventSubscriberTest, FrameEventDelay) { base::TimeTicks now(testing_clock_->NowTicks()); RtpTimestamp rtp_timestamp = 100; int delay_ms = 100; - cast_environment_->Logging()->InsertFrameEventWithDelay( - now, FRAME_PLAYOUT, AUDIO_EVENT, rtp_timestamp, - /*frame_id*/ 0, base::TimeDelta::FromMilliseconds(delay_ms)); + scoped_ptr<FrameEvent> playout_event(new FrameEvent()); + playout_event->timestamp = now; + playout_event->type = FRAME_PLAYOUT; + playout_event->media_type = AUDIO_EVENT; + playout_event->rtp_timestamp = rtp_timestamp; + playout_event->frame_id = 0; + playout_event->delay_delta = base::TimeDelta::FromMilliseconds(delay_ms); + cast_environment_->logger()->DispatchFrameEvent(playout_event.Pass()); GetEventsAndReset(); @@ -241,10 +262,18 @@ TEST_F(EncodingEventSubscriberTest, FrameEventSize) { int target_bitrate = 1024; double encoder_cpu_utilization = 0.90; double idealized_bitrate_utilization = 0.42; - cast_environment_->Logging()->InsertEncodedFrameEvent( - now, FRAME_ENCODED, VIDEO_EVENT, rtp_timestamp, - /*frame_id*/ 0, size, key_frame, target_bitrate, - encoder_cpu_utilization, idealized_bitrate_utilization); + scoped_ptr<FrameEvent> encode_event(new FrameEvent()); + encode_event->timestamp = now; + encode_event->type = FRAME_ENCODED; + encode_event->media_type = VIDEO_EVENT; + encode_event->rtp_timestamp = rtp_timestamp; + encode_event->frame_id = 0; + encode_event->size = size; + encode_event->key_frame = key_frame; + encode_event->target_bitrate = target_bitrate; + encode_event->encoder_cpu_utilization = encoder_cpu_utilization; + encode_event->idealized_bitrate_utilization = idealized_bitrate_utilization; + cast_environment_->logger()->DispatchFrameEvent(encode_event.Pass()); GetEventsAndReset(); @@ -276,22 +305,37 @@ TEST_F(EncodingEventSubscriberTest, MultipleFrameEvents) { RtpTimestamp rtp_timestamp1 = 100; RtpTimestamp rtp_timestamp2 = 200; base::TimeTicks now1(testing_clock_->NowTicks()); - cast_environment_->Logging()->InsertFrameEventWithDelay( - now1, FRAME_PLAYOUT, AUDIO_EVENT, rtp_timestamp1, - /*frame_id*/ 0, /*delay*/ base::TimeDelta::FromMilliseconds(100)); - - testing_clock_->Advance(base::TimeDelta::FromMilliseconds(20)); + scoped_ptr<FrameEvent> playout_event(new FrameEvent()); + playout_event->timestamp = now1; + playout_event->type = FRAME_PLAYOUT; + playout_event->media_type = AUDIO_EVENT; + playout_event->rtp_timestamp = rtp_timestamp1; + playout_event->frame_id = 0; + playout_event->delay_delta = base::TimeDelta::FromMilliseconds(100); + cast_environment_->logger()->DispatchFrameEvent(playout_event.Pass()); + + task_runner_->Sleep(base::TimeDelta::FromMilliseconds(20)); base::TimeTicks now2(testing_clock_->NowTicks()); - cast_environment_->Logging()->InsertEncodedFrameEvent( - now2, FRAME_ENCODED, AUDIO_EVENT, rtp_timestamp2, - /*frame_id*/ 0, /*size*/ 123, /* key_frame - unused */ false, - /*target_bitrate - unused*/ 0, - 0.44, 0.55); - - testing_clock_->Advance(base::TimeDelta::FromMilliseconds(20)); + scoped_ptr<FrameEvent> encode_event(new FrameEvent()); + encode_event->timestamp = now2; + encode_event->type = FRAME_ENCODED; + encode_event->media_type = AUDIO_EVENT; + encode_event->rtp_timestamp = rtp_timestamp2; + encode_event->frame_id = 0; + encode_event->size = 123; + encode_event->encoder_cpu_utilization = 0.44; + encode_event->idealized_bitrate_utilization = 0.55; + cast_environment_->logger()->DispatchFrameEvent(encode_event.Pass()); + + task_runner_->Sleep(base::TimeDelta::FromMilliseconds(20)); base::TimeTicks now3(testing_clock_->NowTicks()); - cast_environment_->Logging()->InsertFrameEvent( - now3, FRAME_DECODED, AUDIO_EVENT, rtp_timestamp1, /*frame_id*/ 0); + scoped_ptr<FrameEvent> decode_event(new FrameEvent()); + decode_event->timestamp = now3; + decode_event->type = FRAME_DECODED; + decode_event->media_type = AUDIO_EVENT; + decode_event->rtp_timestamp = rtp_timestamp1; + decode_event->frame_id = 0; + cast_environment_->logger()->DispatchFrameEvent(decode_event.Pass()); GetEventsAndReset(); @@ -338,10 +382,16 @@ TEST_F(EncodingEventSubscriberTest, PacketEvent) { RtpTimestamp rtp_timestamp = 100; int packet_id = 2; int size = 100; - cast_environment_->Logging()->InsertPacketEvent( - now, PACKET_RECEIVED, AUDIO_EVENT, - rtp_timestamp, /*frame_id*/ 0, packet_id, - /*max_packet_id*/ 10, size); + scoped_ptr<PacketEvent> receive_event(new PacketEvent()); + receive_event->timestamp = now; + receive_event->type = PACKET_RECEIVED; + receive_event->media_type = AUDIO_EVENT; + receive_event->rtp_timestamp = rtp_timestamp; + receive_event->frame_id = 0; + receive_event->packet_id = packet_id; + receive_event->max_packet_id = 10; + receive_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(receive_event.Pass()); GetEventsAndReset(); @@ -374,25 +424,29 @@ TEST_F(EncodingEventSubscriberTest, MultiplePacketEventsForPacket) { RtpTimestamp rtp_timestamp = 100; int packet_id = 2; int size = 100; - cast_environment_->Logging()->InsertPacketEvent(now1, - PACKET_SENT_TO_NETWORK, - VIDEO_EVENT, - rtp_timestamp, - /*frame_id*/ 0, - packet_id, - /*max_packet_id*/ 10, - size); - - testing_clock_->Advance(base::TimeDelta::FromMilliseconds(20)); + scoped_ptr<PacketEvent> send_event(new PacketEvent()); + send_event->timestamp = now1; + send_event->type = PACKET_SENT_TO_NETWORK; + send_event->media_type = VIDEO_EVENT; + send_event->rtp_timestamp = rtp_timestamp; + send_event->frame_id = 0; + send_event->packet_id = packet_id; + send_event->max_packet_id = 10; + send_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(send_event.Pass()); + + task_runner_->Sleep(base::TimeDelta::FromMilliseconds(20)); base::TimeTicks now2(testing_clock_->NowTicks()); - cast_environment_->Logging()->InsertPacketEvent(now2, - PACKET_RETRANSMITTED, - VIDEO_EVENT, - rtp_timestamp, - /*frame_id*/ 0, - packet_id, - /*max_packet_id*/ 10, - size); + scoped_ptr<PacketEvent> retransmit_event(new PacketEvent()); + retransmit_event->timestamp = now2; + retransmit_event->type = PACKET_RETRANSMITTED; + retransmit_event->media_type = VIDEO_EVENT; + retransmit_event->rtp_timestamp = rtp_timestamp; + retransmit_event->frame_id = 0; + retransmit_event->packet_id = packet_id; + retransmit_event->max_packet_id = 10; + retransmit_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(retransmit_event.Pass()); GetEventsAndReset(); @@ -425,25 +479,29 @@ TEST_F(EncodingEventSubscriberTest, MultiplePacketEventsForFrame) { int packet_id_1 = 2; int packet_id_2 = 3; int size = 100; - cast_environment_->Logging()->InsertPacketEvent(now1, - PACKET_SENT_TO_NETWORK, - VIDEO_EVENT, - rtp_timestamp, - /*frame_id*/ 0, - packet_id_1, - /*max_packet_id*/ 10, - size); - - testing_clock_->Advance(base::TimeDelta::FromMilliseconds(20)); + scoped_ptr<PacketEvent> send_event(new PacketEvent()); + send_event->timestamp = now1; + send_event->type = PACKET_SENT_TO_NETWORK; + send_event->media_type = VIDEO_EVENT; + send_event->rtp_timestamp = rtp_timestamp; + send_event->frame_id = 0; + send_event->packet_id = packet_id_1; + send_event->max_packet_id = 10; + send_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(send_event.Pass()); + + task_runner_->Sleep(base::TimeDelta::FromMilliseconds(20)); base::TimeTicks now2(testing_clock_->NowTicks()); - cast_environment_->Logging()->InsertPacketEvent(now2, - PACKET_RETRANSMITTED, - VIDEO_EVENT, - rtp_timestamp, - /*frame_id*/ 0, - packet_id_2, - /*max_packet_id*/ 10, - size); + scoped_ptr<PacketEvent> retransmit_event(new PacketEvent()); + retransmit_event->timestamp = now2; + retransmit_event->type = PACKET_RETRANSMITTED; + retransmit_event->media_type = VIDEO_EVENT; + retransmit_event->rtp_timestamp = rtp_timestamp; + retransmit_event->frame_id = 0; + retransmit_event->packet_id = packet_id_2; + retransmit_event->max_packet_id = 10; + retransmit_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(retransmit_event.Pass()); GetEventsAndReset(); @@ -482,25 +540,29 @@ TEST_F(EncodingEventSubscriberTest, MultiplePacketEvents) { int packet_id_1 = 2; int packet_id_2 = 3; int size = 100; - cast_environment_->Logging()->InsertPacketEvent(now1, - PACKET_SENT_TO_NETWORK, - VIDEO_EVENT, - rtp_timestamp_1, - /*frame_id*/ 0, - packet_id_1, - /*max_packet_id*/ 10, - size); - - testing_clock_->Advance(base::TimeDelta::FromMilliseconds(20)); + scoped_ptr<PacketEvent> send_event(new PacketEvent()); + send_event->timestamp = now1; + send_event->type = PACKET_SENT_TO_NETWORK; + send_event->media_type = VIDEO_EVENT; + send_event->rtp_timestamp = rtp_timestamp_1; + send_event->frame_id = 0; + send_event->packet_id = packet_id_1; + send_event->max_packet_id = 10; + send_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(send_event.Pass()); + + task_runner_->Sleep(base::TimeDelta::FromMilliseconds(20)); base::TimeTicks now2(testing_clock_->NowTicks()); - cast_environment_->Logging()->InsertPacketEvent(now2, - PACKET_RETRANSMITTED, - VIDEO_EVENT, - rtp_timestamp_2, - /*frame_id*/ 0, - packet_id_2, - /*max_packet_id*/ 10, - size); + scoped_ptr<PacketEvent> retransmit_event(new PacketEvent()); + retransmit_event->timestamp = now2; + retransmit_event->type = PACKET_RETRANSMITTED; + retransmit_event->media_type = VIDEO_EVENT; + retransmit_event->rtp_timestamp = rtp_timestamp_2; + retransmit_event->frame_id = 0; + retransmit_event->packet_id = packet_id_2; + retransmit_event->max_packet_id = 10; + retransmit_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(retransmit_event.Pass()); GetEventsAndReset(); @@ -544,16 +606,21 @@ TEST_F(EncodingEventSubscriberTest, FirstRtpTimestamp) { RtpTimestamp rtp_timestamp = 12345; base::TimeTicks now(testing_clock_->NowTicks()); - cast_environment_->Logging()->InsertFrameEvent(now, - FRAME_CAPTURE_BEGIN, - VIDEO_EVENT, - rtp_timestamp, - /*frame_id*/ 0); - - cast_environment_->Logging()->InsertCapturedVideoFrameEvent( - now, - rtp_timestamp + 30, - 1280, 720); + scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent()); + capture_begin_event->timestamp = now; + capture_begin_event->type = FRAME_CAPTURE_BEGIN; + capture_begin_event->media_type = VIDEO_EVENT; + capture_begin_event->rtp_timestamp = rtp_timestamp; + cast_environment_->logger()->DispatchFrameEvent(capture_begin_event.Pass()); + + scoped_ptr<FrameEvent> capture_end_event(new FrameEvent()); + capture_end_event->timestamp = now; + capture_end_event->type = FRAME_CAPTURE_END; + capture_end_event->media_type = VIDEO_EVENT; + capture_end_event->rtp_timestamp = rtp_timestamp + 30; + capture_end_event->width = 1280; + capture_end_event->height = 720; + cast_environment_->logger()->DispatchFrameEvent(capture_end_event.Pass()); GetEventsAndReset(); @@ -570,11 +637,13 @@ TEST_F(EncodingEventSubscriberTest, FirstRtpTimestamp) { rtp_timestamp = 67890; - cast_environment_->Logging()->InsertFrameEvent(now, - FRAME_CAPTURE_BEGIN, - VIDEO_EVENT, - rtp_timestamp, - /*frame_id*/ 0); + capture_begin_event.reset(new FrameEvent()); + capture_begin_event->timestamp = now; + capture_begin_event->type = FRAME_CAPTURE_BEGIN; + capture_begin_event->media_type = VIDEO_EVENT; + capture_begin_event->rtp_timestamp = rtp_timestamp; + cast_environment_->logger()->DispatchFrameEvent(capture_begin_event.Pass()); + GetEventsAndReset(); EXPECT_EQ(rtp_timestamp, first_rtp_timestamp_); @@ -585,17 +654,22 @@ TEST_F(EncodingEventSubscriberTest, RelativeRtpTimestampWrapAround) { RtpTimestamp rtp_timestamp = 0xffffffff - 20; base::TimeTicks now(testing_clock_->NowTicks()); - cast_environment_->Logging()->InsertFrameEvent(now, - FRAME_CAPTURE_BEGIN, - VIDEO_EVENT, - rtp_timestamp, - /*frame_id*/ 0); + scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent()); + capture_begin_event->timestamp = now; + capture_begin_event->type = FRAME_CAPTURE_BEGIN; + capture_begin_event->media_type = VIDEO_EVENT; + capture_begin_event->rtp_timestamp = rtp_timestamp; + cast_environment_->logger()->DispatchFrameEvent(capture_begin_event.Pass()); // RtpTimestamp has now wrapped around. - cast_environment_->Logging()->InsertCapturedVideoFrameEvent( - now, - rtp_timestamp + 30, - 1280, 720); + scoped_ptr<FrameEvent> capture_end_event(new FrameEvent()); + capture_end_event->timestamp = now; + capture_end_event->type = FRAME_CAPTURE_END; + capture_end_event->media_type = VIDEO_EVENT; + capture_end_event->rtp_timestamp = rtp_timestamp + 30; + capture_end_event->width = 1280; + capture_end_event->height = 720; + cast_environment_->logger()->DispatchFrameEvent(capture_end_event.Pass()); GetEventsAndReset(); @@ -614,12 +688,15 @@ TEST_F(EncodingEventSubscriberTest, MaxEventsPerProto) { Init(VIDEO_EVENT); RtpTimestamp rtp_timestamp = 100; for (int i = 0; i < kMaxEventsPerProto + 1; i++) { - cast_environment_->Logging()->InsertFrameEvent(testing_clock_->NowTicks(), - FRAME_ACK_RECEIVED, - VIDEO_EVENT, - rtp_timestamp, - /*frame_id*/ 0); - testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30)); + scoped_ptr<FrameEvent> ack_event(new FrameEvent()); + ack_event->timestamp = testing_clock_->NowTicks(); + ack_event->type = FRAME_ACK_RECEIVED; + ack_event->media_type = VIDEO_EVENT; + ack_event->rtp_timestamp = rtp_timestamp; + ack_event->frame_id = 0; + cast_environment_->logger()->DispatchFrameEvent(ack_event.Pass()); + + task_runner_->Sleep(base::TimeDelta::FromMilliseconds(30)); } GetEventsAndReset(); @@ -633,16 +710,18 @@ TEST_F(EncodingEventSubscriberTest, MaxEventsPerProto) { EXPECT_EQ(kMaxEventsPerProto, frame_event->event_type_size()); for (int i = 0; i < kMaxPacketsPerFrame + 1; i++) { - cast_environment_->Logging()->InsertPacketEvent( - testing_clock_->NowTicks(), - PACKET_SENT_TO_NETWORK, - VIDEO_EVENT, - rtp_timestamp, - /*frame_id*/ 0, - i, - kMaxPacketsPerFrame, - 123); - testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30)); + scoped_ptr<PacketEvent> send_event(new PacketEvent()); + send_event->timestamp = testing_clock_->NowTicks(); + send_event->type = PACKET_SENT_TO_NETWORK; + send_event->media_type = VIDEO_EVENT; + send_event->rtp_timestamp = rtp_timestamp; + send_event->frame_id = 0; + send_event->packet_id = i; + send_event->max_packet_id = kMaxPacketsPerFrame; + send_event->size = 123; + cast_environment_->logger()->DispatchPacketEvent(send_event.Pass()); + + task_runner_->Sleep(base::TimeDelta::FromMilliseconds(30)); } GetEventsAndReset(); @@ -662,16 +741,18 @@ TEST_F(EncodingEventSubscriberTest, MaxEventsPerProto) { EXPECT_EQ(1, packet_event->base_packet_event_size()); for (int j = 0; j < kMaxEventsPerProto + 1; j++) { - cast_environment_->Logging()->InsertPacketEvent( - testing_clock_->NowTicks(), - PACKET_SENT_TO_NETWORK, - VIDEO_EVENT, - rtp_timestamp, - /*frame_id*/ 0, - 0, - 0, - 123); - testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30)); + scoped_ptr<PacketEvent> send_event(new PacketEvent()); + send_event->timestamp = testing_clock_->NowTicks(); + send_event->type = PACKET_SENT_TO_NETWORK; + send_event->media_type = VIDEO_EVENT; + send_event->rtp_timestamp = rtp_timestamp; + send_event->frame_id = 0; + send_event->packet_id = 0; + send_event->max_packet_id = 0; + send_event->size = 123; + cast_environment_->logger()->DispatchPacketEvent(send_event.Pass()); + + task_runner_->Sleep(base::TimeDelta::FromMilliseconds(30)); } GetEventsAndReset(); diff --git a/media/cast/logging/log_event_dispatcher.cc b/media/cast/logging/log_event_dispatcher.cc new file mode 100644 index 0000000..ac0e9ab --- /dev/null +++ b/media/cast/logging/log_event_dispatcher.cc @@ -0,0 +1,137 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/cast/logging/log_event_dispatcher.h" + +#include <algorithm> + +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/location.h" +#include "base/synchronization/waitable_event.h" +#include "media/cast/cast_environment.h" + +namespace media { +namespace cast { + +LogEventDispatcher::LogEventDispatcher(CastEnvironment* env) + : env_(env), impl_(new Impl()) { + DCHECK(env_); +} + +LogEventDispatcher::~LogEventDispatcher() {} + +void LogEventDispatcher::DispatchFrameEvent( + scoped_ptr<FrameEvent> event) const { + if (env_->CurrentlyOn(CastEnvironment::MAIN)) { + impl_->DispatchFrameEvent(event.Pass()); + } else { + env_->PostTask(CastEnvironment::MAIN, FROM_HERE, + base::Bind(&LogEventDispatcher::Impl::DispatchFrameEvent, + impl_, base::Passed(&event))); + } +} + +void LogEventDispatcher::DispatchPacketEvent( + scoped_ptr<PacketEvent> event) const { + if (env_->CurrentlyOn(CastEnvironment::MAIN)) { + impl_->DispatchPacketEvent(event.Pass()); + } else { + env_->PostTask(CastEnvironment::MAIN, FROM_HERE, + base::Bind(&LogEventDispatcher::Impl::DispatchPacketEvent, + impl_, base::Passed(&event))); + } +} + +void LogEventDispatcher::DispatchBatchOfEvents( + scoped_ptr<std::vector<FrameEvent>> frame_events, + scoped_ptr<std::vector<PacketEvent>> packet_events) const { + if (env_->CurrentlyOn(CastEnvironment::MAIN)) { + impl_->DispatchBatchOfEvents(frame_events.Pass(), packet_events.Pass()); + } else { + env_->PostTask( + CastEnvironment::MAIN, FROM_HERE, + base::Bind(&LogEventDispatcher::Impl::DispatchBatchOfEvents, impl_, + base::Passed(&frame_events), base::Passed(&packet_events))); + } +} + +void LogEventDispatcher::Subscribe(RawEventSubscriber* subscriber) { + if (env_->CurrentlyOn(CastEnvironment::MAIN)) { + impl_->Subscribe(subscriber); + } else { + env_->PostTask( + CastEnvironment::MAIN, FROM_HERE, + base::Bind(&LogEventDispatcher::Impl::Subscribe, impl_, subscriber)); + } +} + +void LogEventDispatcher::Unsubscribe(RawEventSubscriber* subscriber) { + if (env_->CurrentlyOn(CastEnvironment::MAIN)) { + impl_->Unsubscribe(subscriber); + } else { + // This method, once it returns, guarantees |subscriber| will not receive + // any more events. Therefore, when called on a thread other than the + // CastEnvironment's MAIN thread, block until the unsubscribe task + // completes. + struct Helper { + static void UnsubscribeAndSignal(const scoped_refptr<Impl>& impl, + RawEventSubscriber* subscriber, + base::WaitableEvent* done) { + impl->Unsubscribe(subscriber); + done->Signal(); + } + }; + base::WaitableEvent done(true, false); + CHECK(env_->PostTask( + CastEnvironment::MAIN, FROM_HERE, + base::Bind(&Helper::UnsubscribeAndSignal, impl_, subscriber, &done))); + done.Wait(); + } +} + +LogEventDispatcher::Impl::Impl() {} + +LogEventDispatcher::Impl::~Impl() { + DCHECK(subscribers_.empty()); +} + +void LogEventDispatcher::Impl::DispatchFrameEvent( + scoped_ptr<FrameEvent> event) const { + for (RawEventSubscriber* s : subscribers_) + s->OnReceiveFrameEvent(*event); +} + +void LogEventDispatcher::Impl::DispatchPacketEvent( + scoped_ptr<PacketEvent> event) const { + for (RawEventSubscriber* s : subscribers_) + s->OnReceivePacketEvent(*event); +} + +void LogEventDispatcher::Impl::DispatchBatchOfEvents( + scoped_ptr<std::vector<FrameEvent>> frame_events, + scoped_ptr<std::vector<PacketEvent>> packet_events) const { + for (RawEventSubscriber* s : subscribers_) { + for (const FrameEvent& e : *frame_events) + s->OnReceiveFrameEvent(e); + for (const PacketEvent& e : *packet_events) + s->OnReceivePacketEvent(e); + } +} + +void LogEventDispatcher::Impl::Subscribe(RawEventSubscriber* subscriber) { + DCHECK(std::find(subscribers_.begin(), subscribers_.end(), subscriber) == + subscribers_.end()); + subscribers_.push_back(subscriber); +} + +void LogEventDispatcher::Impl::Unsubscribe(RawEventSubscriber* subscriber) { + const auto it = + std::find(subscribers_.begin(), subscribers_.end(), subscriber); + DCHECK(it != subscribers_.end()); + subscribers_.erase(it); +} + +} // namespace cast +} // namespace media diff --git a/media/cast/logging/log_event_dispatcher.h b/media/cast/logging/log_event_dispatcher.h new file mode 100644 index 0000000..d84e79b --- /dev/null +++ b/media/cast/logging/log_event_dispatcher.h @@ -0,0 +1,81 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MEDIA_CAST_LOGGING_LOG_EVENT_DISPATCHER_H_ +#define MEDIA_CAST_LOGGING_LOG_EVENT_DISPATCHER_H_ + +#include <vector> + +#include "base/macros.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "media/cast/logging/logging_defines.h" +#include "media/cast/logging/raw_event_subscriber.h" + +namespace media { +namespace cast { + +class CastEnvironment; + +// A thread-safe receiver of logging events that manages an active list of +// EventSubscribers and dispatches the logging events to them on the MAIN +// thread. All methods, constructor, and destructor can be invoked on any +// thread. +class LogEventDispatcher { + public: + // |env| outlives this instance (and generally owns this instance). + explicit LogEventDispatcher(CastEnvironment* env); + + ~LogEventDispatcher(); + + // Called on any thread to schedule the sending of event(s) to all + // EventSubscribers on the MAIN thread. + void DispatchFrameEvent(scoped_ptr<FrameEvent> event) const; + void DispatchPacketEvent(scoped_ptr<PacketEvent> event) const; + void DispatchBatchOfEvents( + scoped_ptr<std::vector<FrameEvent>> frame_events, + scoped_ptr<std::vector<PacketEvent>> packet_events) const; + + // Adds |subscriber| to the active list to begin receiving events on MAIN + // thread. Unsubscribe() must be called before |subscriber| is destroyed. + void Subscribe(RawEventSubscriber* subscriber); + + // Removes |subscriber| from the active list. Once this method returns, the + // |subscriber| is guaranteed not to receive any more events. + void Unsubscribe(RawEventSubscriber* subscriber); + + private: + // The part of the implementation that runs exclusively on the MAIN thread. + class Impl : public base::RefCountedThreadSafe<Impl> { + public: + Impl(); + + void DispatchFrameEvent(scoped_ptr<FrameEvent> event) const; + void DispatchPacketEvent(scoped_ptr<PacketEvent> event) const; + void DispatchBatchOfEvents( + scoped_ptr<std::vector<FrameEvent>> frame_events, + scoped_ptr<std::vector<PacketEvent>> packet_events) const; + void Subscribe(RawEventSubscriber* subscriber); + void Unsubscribe(RawEventSubscriber* subscriber); + + private: + friend class base::RefCountedThreadSafe<Impl>; + + ~Impl(); + + std::vector<RawEventSubscriber*> subscribers_; + + DISALLOW_COPY_AND_ASSIGN(Impl); + }; + + CastEnvironment* const env_; // Owner of this instance. + const scoped_refptr<Impl> impl_; + + DISALLOW_COPY_AND_ASSIGN(LogEventDispatcher); +}; + +} // namespace cast +} // namespace media + +#endif // MEDIA_CAST_LOGGING_LOG_EVENT_DISPATCHER_H_ diff --git a/media/cast/logging/logging_impl.cc b/media/cast/logging/logging_impl.cc deleted file mode 100644 index b64674f..0000000 --- a/media/cast/logging/logging_impl.cc +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/big_endian.h" -#include "base/trace_event/trace_event.h" -#include "media/cast/logging/logging_impl.h" - -namespace media { -namespace cast { - -// TODO(imcheng): Collapse LoggingRaw onto LoggingImpl. -LoggingImpl::LoggingImpl() { - // LoggingImpl can be constructed on any thread, but its methods should all be - // called on the same thread. - thread_checker_.DetachFromThread(); -} - -LoggingImpl::~LoggingImpl() {} - -void LoggingImpl::InsertFrameEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 rtp_timestamp, - uint32 frame_id) { - DCHECK(thread_checker_.CalledOnValidThread()); - raw_.InsertFrameEvent(time_of_event, event, event_media_type, - rtp_timestamp, frame_id); -} - -void LoggingImpl::InsertCapturedVideoFrameEvent( - const base::TimeTicks& time_of_event, - uint32 rtp_timestamp, - int width, - int height) { - DCHECK(thread_checker_.CalledOnValidThread()); - raw_.InsertCapturedVideoFrameEvent( - time_of_event, rtp_timestamp, width, height); -} - - -void LoggingImpl::InsertEncodedFrameEvent( - const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 rtp_timestamp, - uint32 frame_id, - int encoded_size, - bool key_frame, - int target_bitrate, - double encoder_cpu_utilization, - double idealized_bitrate_utilization) { - DCHECK(thread_checker_.CalledOnValidThread()); - raw_.InsertEncodedFrameEvent(time_of_event, event, event_media_type, - rtp_timestamp, frame_id, encoded_size, key_frame, target_bitrate, - encoder_cpu_utilization, idealized_bitrate_utilization); -} - -void LoggingImpl::InsertFrameEventWithDelay( - const base::TimeTicks& time_of_event, CastLoggingEvent event, - EventMediaType event_media_type, uint32 rtp_timestamp, uint32 frame_id, - base::TimeDelta delay) { - DCHECK(thread_checker_.CalledOnValidThread()); - raw_.InsertFrameEventWithDelay(time_of_event, event, event_media_type, - rtp_timestamp, frame_id, delay); -} - -void LoggingImpl::InsertSinglePacketEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - const Packet& packet) { - DCHECK(thread_checker_.CalledOnValidThread()); - - // Parse basic properties. - uint32 rtp_timestamp; - uint16 packet_id, max_packet_id; - const uint8* packet_data = &packet[0]; - base::BigEndianReader big_endian_reader( - reinterpret_cast<const char*>(packet_data + 4), 4); - big_endian_reader.ReadU32(&rtp_timestamp); - base::BigEndianReader cast_big_endian_reader( - reinterpret_cast<const char*>(packet_data + 12 + 2), 4); - cast_big_endian_reader.ReadU16(&packet_id); - cast_big_endian_reader.ReadU16(&max_packet_id); - - // rtp_timestamp is enough - no need for frame_id as well. - InsertPacketEvent(time_of_event, - event, - event_media_type, - rtp_timestamp, - kFrameIdUnknown, - packet_id, - max_packet_id, - packet.size()); -} - -void LoggingImpl::InsertPacketListEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - const PacketList& packets) { - DCHECK(thread_checker_.CalledOnValidThread()); - for (PacketList::const_iterator it = packets.begin(); it != packets.end(); - ++it) { - InsertSinglePacketEvent(time_of_event, event, event_media_type, - (*it)->data); - } -} - -void LoggingImpl::InsertPacketEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 rtp_timestamp, uint32 frame_id, - uint16 packet_id, uint16 max_packet_id, - size_t size) { - DCHECK(thread_checker_.CalledOnValidThread()); - raw_.InsertPacketEvent(time_of_event, event, event_media_type, - rtp_timestamp, frame_id, packet_id, max_packet_id, size); -} - -void LoggingImpl::AddRawEventSubscriber(RawEventSubscriber* subscriber) { - DCHECK(thread_checker_.CalledOnValidThread()); - raw_.AddSubscriber(subscriber); -} - -void LoggingImpl::RemoveRawEventSubscriber(RawEventSubscriber* subscriber) { - DCHECK(thread_checker_.CalledOnValidThread()); - raw_.RemoveSubscriber(subscriber); -} - -} // namespace cast -} // namespace media diff --git a/media/cast/logging/logging_impl.h b/media/cast/logging/logging_impl.h deleted file mode 100644 index 1fc3e76..0000000 --- a/media/cast/logging/logging_impl.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -#ifndef MEDIA_CAST_LOGGING_LOGGING_IMPL_H_ -#define MEDIA_CAST_LOGGING_LOGGING_IMPL_H_ - -// Generic class that handles event logging for the cast library. -// Logging has three possible optional forms: -// 1. Raw data and stats accessible by the application. -// 2. Tracing of raw events. - -#include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" -#include "media/cast/cast_config.h" -#include "media/cast/logging/logging_defines.h" -#include "media/cast/logging/logging_raw.h" - -namespace media { -namespace cast { - -class LoggingImpl { - public: - LoggingImpl(); - ~LoggingImpl(); - - // Note: All methods below should be called from the same thread. - - void InsertFrameEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, EventMediaType event_media_type, - uint32 rtp_timestamp, uint32 frame_id); - - void InsertCapturedVideoFrameEvent(const base::TimeTicks& time_of_event, - uint32 rtp_timestamp, - int width, - int height); - - void InsertEncodedFrameEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 rtp_timestamp, - uint32 frame_id, - int encoded_size, - bool key_frame, - int target_bitrate, - double encoder_cpu_utilization, - double idealized_bitrate_utilization); - - void InsertFrameEventWithDelay(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 rtp_timestamp, uint32 frame_id, - base::TimeDelta delay); - - void InsertSinglePacketEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - const Packet& packet); - - void InsertPacketListEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - const PacketList& packets); - - void InsertPacketEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, uint32 rtp_timestamp, - uint32 frame_id, uint16 packet_id, - uint16 max_packet_id, size_t size); - - // Delegates to |LoggingRaw::AddRawEventSubscriber()|. - void AddRawEventSubscriber(RawEventSubscriber* subscriber); - - // Delegates to |LoggingRaw::RemoveRawEventSubscriber()|. - void RemoveRawEventSubscriber(RawEventSubscriber* subscriber); - - private: - base::ThreadChecker thread_checker_; - LoggingRaw raw_; - - DISALLOW_COPY_AND_ASSIGN(LoggingImpl); -}; - -} // namespace cast -} // namespace media - -#endif // MEDIA_CAST_LOGGING_LOGGING_IMPL_H_ diff --git a/media/cast/logging/logging_impl_unittest.cc b/media/cast/logging/logging_impl_unittest.cc deleted file mode 100644 index fb2779c..0000000 --- a/media/cast/logging/logging_impl_unittest.cc +++ /dev/null @@ -1,235 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <stdint.h> - -#include <vector> - -#include "base/rand_util.h" -#include "base/test/simple_test_tick_clock.h" -#include "base/time/tick_clock.h" -#include "base/time/time.h" -#include "media/cast/logging/logging_defines.h" -#include "media/cast/logging/logging_impl.h" -#include "media/cast/logging/simple_event_subscriber.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace media { -namespace cast { - -// Insert frame duration- one second. -const int64 kIntervalTime1S = 1; -// Test frame rate goal - 30fps. -const int kFrameIntervalMs = 33; - -static const int64 kStartMillisecond = INT64_C(12345678900000); - -class LoggingImplTest : public ::testing::Test { - protected: - LoggingImplTest() { - testing_clock_.Advance( - base::TimeDelta::FromMilliseconds(kStartMillisecond)); - logging_.AddRawEventSubscriber(&event_subscriber_); - } - - ~LoggingImplTest() override { - logging_.RemoveRawEventSubscriber(&event_subscriber_); - } - - LoggingImpl logging_; - base::SimpleTestTickClock testing_clock_; - SimpleEventSubscriber event_subscriber_; - - DISALLOW_COPY_AND_ASSIGN(LoggingImplTest); -}; - -TEST_F(LoggingImplTest, BasicFrameLogging) { - base::TimeTicks start_time = testing_clock_.NowTicks(); - base::TimeDelta time_interval = testing_clock_.NowTicks() - start_time; - uint32 rtp_timestamp = 0; - uint32 frame_id = 0; - base::TimeTicks now; - do { - now = testing_clock_.NowTicks(); - logging_.InsertFrameEvent( - now, FRAME_CAPTURE_BEGIN, VIDEO_EVENT, rtp_timestamp, frame_id); - testing_clock_.Advance( - base::TimeDelta::FromMilliseconds(kFrameIntervalMs)); - rtp_timestamp += kFrameIntervalMs * 90; - ++frame_id; - time_interval = now - start_time; - } while (time_interval.InSeconds() < kIntervalTime1S); - - // Get logging data. - std::vector<FrameEvent> frame_events; - event_subscriber_.GetFrameEventsAndReset(&frame_events); - // Size of vector should be equal to the number of events logged, - // which equals to number of frames in this case. - EXPECT_EQ(frame_id, frame_events.size()); -} - -TEST_F(LoggingImplTest, FrameLoggingWithSize) { - // Average packet size. - const int kBaseFrameSizeBytes = 25000; - const int kRandomSizeInterval = 100; - base::TimeTicks start_time = testing_clock_.NowTicks(); - base::TimeDelta time_interval = testing_clock_.NowTicks() - start_time; - uint32 rtp_timestamp = 0; - uint32 frame_id = 0; - size_t sum_size = 0; - int target_bitrate = 1234; - do { - int size = kBaseFrameSizeBytes + - base::RandInt(-kRandomSizeInterval, kRandomSizeInterval); - sum_size += static_cast<size_t>(size); - logging_.InsertEncodedFrameEvent(testing_clock_.NowTicks(), - FRAME_ENCODED, VIDEO_EVENT, rtp_timestamp, - frame_id, size, true, target_bitrate, - 0.1, 2.3); - testing_clock_.Advance(base::TimeDelta::FromMilliseconds(kFrameIntervalMs)); - rtp_timestamp += kFrameIntervalMs * 90; - ++frame_id; - time_interval = testing_clock_.NowTicks() - start_time; - } while (time_interval.InSeconds() < kIntervalTime1S); - // Get logging data. - std::vector<FrameEvent> frame_events; - event_subscriber_.GetFrameEventsAndReset(&frame_events); - // Size of vector should be equal to the number of events logged, which - // equals to number of frames in this case. - EXPECT_EQ(frame_id, frame_events.size()); -} - -TEST_F(LoggingImplTest, FrameLoggingWithDelay) { - // Average packet size. - const int kPlayoutDelayMs = 50; - const int kRandomSizeInterval = 20; - base::TimeTicks start_time = testing_clock_.NowTicks(); - base::TimeDelta time_interval = testing_clock_.NowTicks() - start_time; - uint32 rtp_timestamp = 0; - uint32 frame_id = 0; - do { - int delay = kPlayoutDelayMs + - base::RandInt(-kRandomSizeInterval, kRandomSizeInterval); - logging_.InsertFrameEventWithDelay( - testing_clock_.NowTicks(), - FRAME_CAPTURE_BEGIN, - VIDEO_EVENT, - rtp_timestamp, - frame_id, - base::TimeDelta::FromMilliseconds(delay)); - testing_clock_.Advance(base::TimeDelta::FromMilliseconds(kFrameIntervalMs)); - rtp_timestamp += kFrameIntervalMs * 90; - ++frame_id; - time_interval = testing_clock_.NowTicks() - start_time; - } while (time_interval.InSeconds() < kIntervalTime1S); - // Get logging data. - std::vector<FrameEvent> frame_events; - event_subscriber_.GetFrameEventsAndReset(&frame_events); - // Size of vector should be equal to the number of frames logged. - EXPECT_EQ(frame_id, frame_events.size()); -} - -TEST_F(LoggingImplTest, MultipleEventFrameLogging) { - base::TimeTicks start_time = testing_clock_.NowTicks(); - base::TimeDelta time_interval = testing_clock_.NowTicks() - start_time; - uint32 rtp_timestamp = 0u; - uint32 frame_id = 0u; - uint32 num_events = 0u; - do { - logging_.InsertFrameEvent(testing_clock_.NowTicks(), - FRAME_CAPTURE_END, - VIDEO_EVENT, - rtp_timestamp, - frame_id); - ++num_events; - if (frame_id % 2) { - logging_.InsertEncodedFrameEvent(testing_clock_.NowTicks(), - FRAME_ENCODED, AUDIO_EVENT, - rtp_timestamp, - frame_id, 1500, true, 0, 4.5, 6.7); - } else if (frame_id % 3) { - logging_.InsertFrameEvent(testing_clock_.NowTicks(), FRAME_DECODED, - VIDEO_EVENT, rtp_timestamp, frame_id); - } else { - logging_.InsertFrameEventWithDelay( - testing_clock_.NowTicks(), FRAME_PLAYOUT, VIDEO_EVENT, - rtp_timestamp, frame_id, base::TimeDelta::FromMilliseconds(20)); - } - ++num_events; - - testing_clock_.Advance(base::TimeDelta::FromMilliseconds(kFrameIntervalMs)); - rtp_timestamp += kFrameIntervalMs * 90; - ++frame_id; - time_interval = testing_clock_.NowTicks() - start_time; - } while (time_interval.InSeconds() < kIntervalTime1S); - // Get logging data. - std::vector<FrameEvent> frame_events; - event_subscriber_.GetFrameEventsAndReset(&frame_events); - // Size of vector should be equal to the number of frames logged. - EXPECT_EQ(num_events, frame_events.size()); - // Multiple events captured per frame. -} - -TEST_F(LoggingImplTest, PacketLogging) { - const int kNumPacketsPerFrame = 10; - const int kBaseSize = 2500; - const int kSizeInterval = 100; - base::TimeTicks start_time = testing_clock_.NowTicks(); - base::TimeTicks latest_time; - base::TimeDelta time_interval = testing_clock_.NowTicks() - start_time; - RtpTimestamp rtp_timestamp = 0; - int frame_id = 0; - int num_packets = 0; - int sum_size = 0u; - do { - for (int i = 0; i < kNumPacketsPerFrame; ++i) { - int size = kBaseSize + base::RandInt(-kSizeInterval, kSizeInterval); - sum_size += size; - latest_time = testing_clock_.NowTicks(); - ++num_packets; - logging_.InsertPacketEvent(latest_time, - PACKET_RECEIVED, - VIDEO_EVENT, - rtp_timestamp, - frame_id, - i, - kNumPacketsPerFrame, - size); - } - testing_clock_.Advance(base::TimeDelta::FromMilliseconds(kFrameIntervalMs)); - rtp_timestamp += kFrameIntervalMs * 90; - ++frame_id; - time_interval = testing_clock_.NowTicks() - start_time; - } while (time_interval.InSeconds() < kIntervalTime1S); - // Get logging data. - std::vector<PacketEvent> packet_events; - event_subscriber_.GetPacketEventsAndReset(&packet_events); - // Size of vector should be equal to the number of packets logged. - EXPECT_EQ(num_packets, static_cast<int>(packet_events.size())); -} - -TEST_F(LoggingImplTest, MultipleRawEventSubscribers) { - SimpleEventSubscriber event_subscriber_2; - - // Now logging_ has two subscribers. - logging_.AddRawEventSubscriber(&event_subscriber_2); - - logging_.InsertFrameEvent(testing_clock_.NowTicks(), - FRAME_CAPTURE_BEGIN, - VIDEO_EVENT, - /*rtp_timestamp*/ 0u, - /*frame_id*/ 0u); - - std::vector<FrameEvent> frame_events; - event_subscriber_.GetFrameEventsAndReset(&frame_events); - EXPECT_EQ(1u, frame_events.size()); - frame_events.clear(); - event_subscriber_2.GetFrameEventsAndReset(&frame_events); - EXPECT_EQ(1u, frame_events.size()); - - logging_.RemoveRawEventSubscriber(&event_subscriber_2); -} - -} // namespace cast -} // namespace media diff --git a/media/cast/logging/logging_raw.cc b/media/cast/logging/logging_raw.cc deleted file mode 100644 index b80c05e..0000000 --- a/media/cast/logging/logging_raw.cc +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/cast/logging/logging_raw.h" - -#include <algorithm> - -#include "base/logging.h" -#include "base/time/time.h" - -namespace media { -namespace cast { - -LoggingRaw::LoggingRaw() {} - -LoggingRaw::~LoggingRaw() {} - -void LoggingRaw::InsertFrameEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 rtp_timestamp, - uint32 frame_id) { - InsertBaseFrameEvent(time_of_event, event, event_media_type, frame_id, - rtp_timestamp, base::TimeDelta(), 0, 0, 0, false, 0, - -1.0, -1.0); -} - -void LoggingRaw::InsertCapturedVideoFrameEvent( - const base::TimeTicks& time_of_event, - uint32 rtp_timestamp, - int width, - int height) { - InsertBaseFrameEvent(time_of_event, FRAME_CAPTURE_END, VIDEO_EVENT, - kFrameIdUnknown, rtp_timestamp, base::TimeDelta(), width, - height, 0, false, 0, -1.0, -1.0); -} - -void LoggingRaw::InsertEncodedFrameEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 rtp_timestamp, - uint32 frame_id, - int encoded_size, - bool key_frame, - int target_bitrate, - double encoder_cpu_utilization, - double idealized_bitrate_utilization) { - InsertBaseFrameEvent(time_of_event, event, event_media_type, - frame_id, rtp_timestamp, base::TimeDelta(), - 0, 0, encoded_size, key_frame, target_bitrate, - encoder_cpu_utilization, idealized_bitrate_utilization); -} - -void LoggingRaw::InsertFrameEventWithDelay(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 rtp_timestamp, - uint32 frame_id, - base::TimeDelta delay) { - InsertBaseFrameEvent(time_of_event, event, event_media_type, frame_id, - rtp_timestamp, delay, 0, 0, 0, false, 0, -1.0, -1.0); -} - -void LoggingRaw::InsertBaseFrameEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 frame_id, - uint32 rtp_timestamp, - base::TimeDelta delay, - int width, - int height, - int encoded_size, - bool key_frame, - int target_bitrate, - double encoder_cpu_utilization, - double idealized_bitrate_utilization) { - FrameEvent frame_event; - frame_event.rtp_timestamp = rtp_timestamp; - frame_event.frame_id = frame_id; - frame_event.width = width; - frame_event.height = height; - frame_event.size = encoded_size; - frame_event.timestamp = time_of_event; - frame_event.type = event; - frame_event.media_type = event_media_type; - frame_event.delay_delta = delay; - frame_event.key_frame = key_frame; - frame_event.target_bitrate = target_bitrate; - frame_event.encoder_cpu_utilization = encoder_cpu_utilization; - frame_event.idealized_bitrate_utilization = idealized_bitrate_utilization; - for (std::vector<RawEventSubscriber*>::const_iterator it = - subscribers_.begin(); - it != subscribers_.end(); ++it) { - (*it)->OnReceiveFrameEvent(frame_event); - } -} - -void LoggingRaw::InsertPacketEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 rtp_timestamp, - uint32 frame_id, uint16 packet_id, - uint16 max_packet_id, size_t size) { - PacketEvent packet_event; - packet_event.rtp_timestamp = rtp_timestamp; - packet_event.frame_id = frame_id; - packet_event.max_packet_id = max_packet_id; - packet_event.packet_id = packet_id; - packet_event.size = size; - packet_event.timestamp = time_of_event; - packet_event.type = event; - packet_event.media_type = event_media_type; - for (std::vector<RawEventSubscriber*>::const_iterator it = - subscribers_.begin(); - it != subscribers_.end(); ++it) { - (*it)->OnReceivePacketEvent(packet_event); - } -} - -void LoggingRaw::AddSubscriber(RawEventSubscriber* subscriber) { - DCHECK(subscriber); - DCHECK(std::find(subscribers_.begin(), subscribers_.end(), subscriber) == - subscribers_.end()); - - subscribers_.push_back(subscriber); -} - -void LoggingRaw::RemoveSubscriber(RawEventSubscriber* subscriber) { - DCHECK(subscriber); - DCHECK(std::find(subscribers_.begin(), subscribers_.end(), subscriber) != - subscribers_.end()); - - subscribers_.erase( - std::remove(subscribers_.begin(), subscribers_.end(), subscriber), - subscribers_.end()); -} - -} // namespace cast -} // namespace media diff --git a/media/cast/logging/logging_raw.h b/media/cast/logging/logging_raw.h deleted file mode 100644 index 49ec985..0000000 --- a/media/cast/logging/logging_raw.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_CAST_LOGGING_LOGGING_RAW_H_ -#define MEDIA_CAST_LOGGING_LOGGING_RAW_H_ - -#include <vector> - -#include "base/basictypes.h" -#include "base/memory/linked_ptr.h" -#include "base/threading/non_thread_safe.h" -#include "base/time/tick_clock.h" -#include "media/cast/logging/logging_defines.h" -#include "media/cast/logging/raw_event_subscriber.h" - -namespace media { -namespace cast { - -// This class is not thread safe, and should only be called from the main -// thread. -class LoggingRaw : public base::NonThreadSafe { - public: - LoggingRaw(); - ~LoggingRaw(); - - // Inform of new event: two types of events: frame and packet. - // Frame events can be inserted with different parameters. - void InsertFrameEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, EventMediaType event_media_type, - uint32 rtp_timestamp, uint32 frame_id); - - // Inserts a FRAME_CAPTURE_END event with the VIDEO_EVENT media type. - void InsertCapturedVideoFrameEvent(const base::TimeTicks& time_of_event, - uint32 rtp_timestamp, - int width, - int height); - - // This function is only applicable for FRAME_ENCODED event. - // |encoded_size| - Size of encoded frame in bytes. - // |key_frame| - Whether the frame is a key frame. This field is only - // applicable for video event. - // |target_bitrate| - The target bitrate of the encoder the time the frame - // was encoded. Only applicable for video event. - void InsertEncodedFrameEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 rtp_timestamp, - uint32 frame_id, - int encoded_size, - bool key_frame, - int target_bitrate, - double encoder_cpu_utilization, - double idealized_bitrate_utilization); - - // Render/playout delay - // This function is only applicable for FRAME_PLAYOUT event. - void InsertFrameEventWithDelay(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 rtp_timestamp, - uint32 frame_id, base::TimeDelta delay); - - // Insert a packet event. - void InsertPacketEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, uint32 rtp_timestamp, - uint32 frame_id, uint16 packet_id, - uint16 max_packet_id, size_t size); - - // Adds |subscriber| so that it will start receiving events on main thread. - // Note that this class does not own |subscriber|. - // It is a no-op to add a subscriber that already exists. - void AddSubscriber(RawEventSubscriber* subscriber); - - // Removes |subscriber| so that it will stop receiving events. - // Note that this class does NOT own the subscribers. This function MUST be - // called before |subscriber| is destroyed if it was previously added. - // It is a no-op to remove a subscriber that doesn't exist. - void RemoveSubscriber(RawEventSubscriber* subscriber); - - private: - void InsertBaseFrameEvent(const base::TimeTicks& time_of_event, - CastLoggingEvent event, - EventMediaType event_media_type, - uint32 frame_id, - uint32 rtp_timestamp, - base::TimeDelta delay, - int width, - int height, - int encoded_size, - bool key_frame, - int target_bitrate, - double encoder_cpu_utilization, - double idealized_bitrate_utilization); - - // List of subscriber pointers. This class does not own the subscribers. - std::vector<RawEventSubscriber*> subscribers_; - - DISALLOW_COPY_AND_ASSIGN(LoggingRaw); -}; - -} // namespace cast -} // namespace media - -#endif // MEDIA_CAST_LOGGING_LOGGING_RAW_H_ diff --git a/media/cast/logging/logging_raw_unittest.cc b/media/cast/logging/logging_raw_unittest.cc deleted file mode 100644 index 0ecfbbf..0000000 --- a/media/cast/logging/logging_raw_unittest.cc +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/cast/logging/logging_defines.h" -#include "media/cast/logging/logging_raw.h" -#include "media/cast/logging/simple_event_subscriber.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace media { -namespace cast { - -class LoggingRawTest : public ::testing::Test { - protected: - LoggingRawTest() { - raw_.AddSubscriber(&event_subscriber_); - } - - ~LoggingRawTest() override { raw_.RemoveSubscriber(&event_subscriber_); } - - LoggingRaw raw_; - SimpleEventSubscriber event_subscriber_; - std::vector<FrameEvent> frame_events_; - std::vector<PacketEvent> packet_events_; -}; - -TEST_F(LoggingRawTest, FrameEvent) { - CastLoggingEvent event_type = FRAME_DECODED; - EventMediaType media_type = VIDEO_EVENT; - uint32 frame_id = 456u; - RtpTimestamp rtp_timestamp = 123u; - base::TimeTicks timestamp = base::TimeTicks(); - raw_.InsertFrameEvent(timestamp, event_type, media_type, - rtp_timestamp, frame_id); - - event_subscriber_.GetPacketEventsAndReset(&packet_events_); - EXPECT_TRUE(packet_events_.empty()); - - event_subscriber_.GetFrameEventsAndReset(&frame_events_); - ASSERT_EQ(1u, frame_events_.size()); - EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp); - EXPECT_EQ(frame_id, frame_events_[0].frame_id); - EXPECT_EQ(0u, frame_events_[0].size); - EXPECT_EQ(timestamp, frame_events_[0].timestamp); - EXPECT_EQ(event_type, frame_events_[0].type); - EXPECT_EQ(media_type, frame_events_[0].media_type); - EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta); -} - -TEST_F(LoggingRawTest, EncodedFrameEvent) { - CastLoggingEvent event_type = FRAME_ENCODED; - EventMediaType media_type = VIDEO_EVENT; - uint32 frame_id = 456u; - RtpTimestamp rtp_timestamp = 123u; - base::TimeTicks timestamp = base::TimeTicks(); - int size = 1024; - bool key_frame = true; - int target_bitrate = 4096; - double encoder_cpu_utilization = 0.11; - double idealized_bitrate_utilization = 0.98; - raw_.InsertEncodedFrameEvent(timestamp, event_type, media_type, - rtp_timestamp, frame_id, size, key_frame, target_bitrate, - encoder_cpu_utilization, idealized_bitrate_utilization); - - event_subscriber_.GetPacketEventsAndReset(&packet_events_); - EXPECT_TRUE(packet_events_.empty()); - - event_subscriber_.GetFrameEventsAndReset(&frame_events_); - ASSERT_EQ(1u, frame_events_.size()); - EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp); - EXPECT_EQ(frame_id, frame_events_[0].frame_id); - EXPECT_EQ(size, static_cast<int>(frame_events_[0].size)); - EXPECT_EQ(timestamp, frame_events_[0].timestamp); - EXPECT_EQ(event_type, frame_events_[0].type); - EXPECT_EQ(media_type, frame_events_[0].media_type); - EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta); - EXPECT_EQ(key_frame, frame_events_[0].key_frame); - EXPECT_EQ(target_bitrate, frame_events_[0].target_bitrate); - EXPECT_EQ(encoder_cpu_utilization, frame_events_[0].encoder_cpu_utilization); - EXPECT_EQ(idealized_bitrate_utilization, - frame_events_[0].idealized_bitrate_utilization); -} - -TEST_F(LoggingRawTest, FrameEventWithDelay) { - CastLoggingEvent event_type = FRAME_PLAYOUT; - EventMediaType media_type = VIDEO_EVENT; - uint32 frame_id = 456u; - RtpTimestamp rtp_timestamp = 123u; - base::TimeTicks timestamp = base::TimeTicks(); - base::TimeDelta delay = base::TimeDelta::FromMilliseconds(20); - raw_.InsertFrameEventWithDelay(timestamp, event_type, media_type, - rtp_timestamp, frame_id, delay); - - event_subscriber_.GetPacketEventsAndReset(&packet_events_); - EXPECT_TRUE(packet_events_.empty()); - - event_subscriber_.GetFrameEventsAndReset(&frame_events_); - ASSERT_EQ(1u, frame_events_.size()); - EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp); - EXPECT_EQ(frame_id, frame_events_[0].frame_id); - EXPECT_EQ(0u, frame_events_[0].size); - EXPECT_EQ(timestamp, frame_events_[0].timestamp); - EXPECT_EQ(event_type, frame_events_[0].type); - EXPECT_EQ(media_type, frame_events_[0].media_type); - EXPECT_EQ(delay, frame_events_[0].delay_delta); -} - -TEST_F(LoggingRawTest, PacketEvent) { - CastLoggingEvent event_type = PACKET_RECEIVED; - EventMediaType media_type = VIDEO_EVENT; - uint32 frame_id = 456u; - uint16 packet_id = 1u; - uint16 max_packet_id = 10u; - RtpTimestamp rtp_timestamp = 123u; - base::TimeTicks timestamp = base::TimeTicks(); - size_t size = 1024u; - raw_.InsertPacketEvent(timestamp, event_type, media_type, - rtp_timestamp, frame_id, packet_id, max_packet_id, size); - - event_subscriber_.GetFrameEventsAndReset(&frame_events_); - EXPECT_TRUE(frame_events_.empty()); - - event_subscriber_.GetPacketEventsAndReset(&packet_events_); - ASSERT_EQ(1u, packet_events_.size()); - - EXPECT_EQ(rtp_timestamp, packet_events_[0].rtp_timestamp); - EXPECT_EQ(frame_id, packet_events_[0].frame_id); - EXPECT_EQ(max_packet_id, packet_events_[0].max_packet_id); - EXPECT_EQ(packet_id, packet_events_[0].packet_id); - EXPECT_EQ(size, packet_events_[0].size); - EXPECT_EQ(timestamp, packet_events_[0].timestamp); - EXPECT_EQ(event_type, packet_events_[0].type); - EXPECT_EQ(media_type, packet_events_[0].media_type); -} - -TEST_F(LoggingRawTest, MultipleSubscribers) { - SimpleEventSubscriber event_subscriber_2; - - // Now raw_ has two subscribers. - raw_.AddSubscriber(&event_subscriber_2); - - CastLoggingEvent event_type = FRAME_DECODED; - EventMediaType media_type = VIDEO_EVENT; - uint32 frame_id = 456u; - RtpTimestamp rtp_timestamp = 123u; - base::TimeTicks timestamp = base::TimeTicks(); - raw_.InsertFrameEvent(timestamp, event_type, media_type, - rtp_timestamp, frame_id); - - event_subscriber_.GetPacketEventsAndReset(&packet_events_); - EXPECT_TRUE(packet_events_.empty()); - - event_subscriber_.GetFrameEventsAndReset(&frame_events_); - ASSERT_EQ(1u, frame_events_.size()); - EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp); - EXPECT_EQ(frame_id, frame_events_[0].frame_id); - EXPECT_EQ(0u, frame_events_[0].size); - EXPECT_EQ(timestamp, frame_events_[0].timestamp); - EXPECT_EQ(event_type, frame_events_[0].type); - EXPECT_EQ(media_type, frame_events_[0].media_type); - EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta); - - event_subscriber_2.GetPacketEventsAndReset(&packet_events_); - EXPECT_TRUE(packet_events_.empty()); - - event_subscriber_2.GetFrameEventsAndReset(&frame_events_); - ASSERT_EQ(1u, frame_events_.size()); - EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp); - EXPECT_EQ(frame_id, frame_events_[0].frame_id); - EXPECT_EQ(0u, frame_events_[0].size); - EXPECT_EQ(timestamp, frame_events_[0].timestamp); - EXPECT_EQ(event_type, frame_events_[0].type); - EXPECT_EQ(media_type, frame_events_[0].media_type); - EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta); - - // Remove event_subscriber_2, so it shouldn't receive events after this. - raw_.RemoveSubscriber(&event_subscriber_2); - - media_type = AUDIO_EVENT; - frame_id = 789; - rtp_timestamp = 456; - timestamp = base::TimeTicks(); - raw_.InsertFrameEvent(timestamp, event_type, media_type, - rtp_timestamp, frame_id); - - // |event_subscriber_| should still receive events. - event_subscriber_.GetFrameEventsAndReset(&frame_events_); - ASSERT_EQ(1u, frame_events_.size()); - EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp); - EXPECT_EQ(frame_id, frame_events_[0].frame_id); - EXPECT_EQ(0u, frame_events_[0].size); - EXPECT_EQ(timestamp, frame_events_[0].timestamp); - EXPECT_EQ(event_type, frame_events_[0].type); - EXPECT_EQ(media_type, frame_events_[0].media_type); - EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta); - - event_subscriber_2.GetFrameEventsAndReset(&frame_events_); - EXPECT_TRUE(frame_events_.empty()); -} - -} // namespace cast -} // namespace media diff --git a/media/cast/logging/raw_event_subscriber_bundle.cc b/media/cast/logging/raw_event_subscriber_bundle.cc index 5dc5f79..ecfe10d 100644 --- a/media/cast/logging/raw_event_subscriber_bundle.cc +++ b/media/cast/logging/raw_event_subscriber_bundle.cc @@ -21,13 +21,13 @@ RawEventSubscriberBundleForStream::RawEventSubscriberBundleForStream( stats_subscriber_( is_audio ? AUDIO_EVENT : VIDEO_EVENT, cast_environment->Clock(), offset_estimator) { - cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber_); - cast_environment_->Logging()->AddRawEventSubscriber(&stats_subscriber_); + cast_environment_->logger()->Subscribe(&event_subscriber_); + cast_environment_->logger()->Subscribe(&stats_subscriber_); } RawEventSubscriberBundleForStream::~RawEventSubscriberBundleForStream() { - cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber_); - cast_environment_->Logging()->RemoveRawEventSubscriber(&stats_subscriber_); + cast_environment_->logger()->Unsubscribe(&event_subscriber_); + cast_environment_->logger()->Unsubscribe(&stats_subscriber_); } EncodingEventSubscriber* @@ -45,17 +45,14 @@ RawEventSubscriberBundle::RawEventSubscriberBundle( : cast_environment_(cast_environment) {} RawEventSubscriberBundle::~RawEventSubscriberBundle() { - if (receiver_offset_estimator_.get()) { - cast_environment_->Logging()->RemoveRawEventSubscriber( - receiver_offset_estimator_.get()); - } + if (receiver_offset_estimator_.get()) + cast_environment_->logger()->Unsubscribe(receiver_offset_estimator_.get()); } void RawEventSubscriberBundle::AddEventSubscribers(bool is_audio) { if (!receiver_offset_estimator_.get()) { receiver_offset_estimator_.reset(new ReceiverTimeOffsetEstimatorImpl); - cast_environment_->Logging()->AddRawEventSubscriber( - receiver_offset_estimator_.get()); + cast_environment_->logger()->Subscribe(receiver_offset_estimator_.get()); } SubscribersMapByStream::iterator it = subscribers_.find(is_audio); if (it != subscribers_.end()) @@ -74,8 +71,7 @@ void RawEventSubscriberBundle::RemoveEventSubscribers(bool is_audio) { subscribers_.erase(it); if (subscribers_.empty()) { - cast_environment_->Logging()->RemoveRawEventSubscriber( - receiver_offset_estimator_.get()); + cast_environment_->logger()->Unsubscribe(receiver_offset_estimator_.get()); receiver_offset_estimator_.reset(); } } diff --git a/media/cast/logging/receiver_time_offset_estimator_impl_unittest.cc b/media/cast/logging/receiver_time_offset_estimator_impl_unittest.cc index ca791d4..2cbaafd 100644 --- a/media/cast/logging/receiver_time_offset_estimator_impl_unittest.cc +++ b/media/cast/logging/receiver_time_offset_estimator_impl_unittest.cc @@ -25,15 +25,15 @@ class ReceiverTimeOffsetEstimatorImplTest : public ::testing::Test { task_runner_, task_runner_, task_runner_)) { - cast_environment_->Logging()->AddRawEventSubscriber(&estimator_); + cast_environment_->logger()->Subscribe(&estimator_); } ~ReceiverTimeOffsetEstimatorImplTest() override { - cast_environment_->Logging()->RemoveRawEventSubscriber(&estimator_); + cast_environment_->logger()->Unsubscribe(&estimator_); } void AdvanceClocks(base::TimeDelta time) { - sender_clock_->Advance(time); + task_runner_->Sleep(time); receiver_clock_.Advance(time); } @@ -63,44 +63,62 @@ TEST_F(ReceiverTimeOffsetEstimatorImplTest, EstimateOffset) { AdvanceClocks(base::TimeDelta::FromMilliseconds(20)); - cast_environment_->Logging()->InsertEncodedFrameEvent( - sender_clock_->NowTicks(), - FRAME_ENCODED, VIDEO_EVENT, - rtp_timestamp, - frame_id, - 1234, - true, - 5678, - 9.10, - 11.12); - - cast_environment_->Logging()->InsertPacketEvent( - sender_clock_->NowTicks(), - PACKET_SENT_TO_NETWORK, VIDEO_EVENT, - rtp_timestamp, - frame_id, - 56, 78, 1500); + scoped_ptr<FrameEvent> encode_event(new FrameEvent()); + encode_event->timestamp = sender_clock_->NowTicks(); + encode_event->type = FRAME_ENCODED; + encode_event->media_type = VIDEO_EVENT; + encode_event->rtp_timestamp = rtp_timestamp; + encode_event->frame_id = frame_id; + encode_event->size = 1234; + encode_event->key_frame = true; + encode_event->target_bitrate = 5678; + encode_event->encoder_cpu_utilization = 9.10; + encode_event->idealized_bitrate_utilization = 11.12; + cast_environment_->logger()->DispatchFrameEvent(encode_event.Pass()); + + scoped_ptr<PacketEvent> send_event(new PacketEvent()); + send_event->timestamp = sender_clock_->NowTicks(); + send_event->type = PACKET_SENT_TO_NETWORK; + send_event->media_type = VIDEO_EVENT; + send_event->rtp_timestamp = rtp_timestamp; + send_event->frame_id = frame_id; + send_event->packet_id = 56; + send_event->max_packet_id = 78; + send_event->size = 1500; + cast_environment_->logger()->DispatchPacketEvent(send_event.Pass()); EXPECT_FALSE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); AdvanceClocks(base::TimeDelta::FromMilliseconds(10)); - cast_environment_->Logging()->InsertFrameEvent( - receiver_clock_.NowTicks(), FRAME_ACK_SENT, VIDEO_EVENT, - rtp_timestamp, frame_id); - - cast_environment_->Logging()->InsertPacketEvent( - receiver_clock_.NowTicks(), - PACKET_RECEIVED, VIDEO_EVENT, - rtp_timestamp, - frame_id, - 56, 78, 1500); + scoped_ptr<FrameEvent> ack_sent_event(new FrameEvent()); + ack_sent_event->timestamp = receiver_clock_.NowTicks(); + ack_sent_event->type = FRAME_ACK_SENT; + ack_sent_event->media_type = VIDEO_EVENT; + ack_sent_event->rtp_timestamp = rtp_timestamp; + ack_sent_event->frame_id = frame_id; + cast_environment_->logger()->DispatchFrameEvent(ack_sent_event.Pass()); + + scoped_ptr<PacketEvent> receive_event(new PacketEvent()); + receive_event->timestamp = receiver_clock_.NowTicks(); + receive_event->type = PACKET_RECEIVED; + receive_event->media_type = VIDEO_EVENT; + receive_event->rtp_timestamp = rtp_timestamp; + receive_event->frame_id = frame_id; + receive_event->packet_id = 56; + receive_event->max_packet_id = 78; + receive_event->size = 1500; + cast_environment_->logger()->DispatchPacketEvent(receive_event.Pass()); EXPECT_FALSE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); AdvanceClocks(base::TimeDelta::FromMilliseconds(30)); - cast_environment_->Logging()->InsertFrameEvent( - sender_clock_->NowTicks(), FRAME_ACK_RECEIVED, VIDEO_EVENT, - rtp_timestamp, frame_id); + scoped_ptr<FrameEvent> ack_event(new FrameEvent()); + ack_event->timestamp = sender_clock_->NowTicks(); + ack_event->type = FRAME_ACK_RECEIVED; + ack_event->media_type = VIDEO_EVENT; + ack_event->rtp_timestamp = rtp_timestamp; + ack_event->frame_id = frame_id; + cast_environment_->logger()->DispatchFrameEvent(ack_event.Pass()); EXPECT_TRUE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); @@ -112,7 +130,7 @@ TEST_F(ReceiverTimeOffsetEstimatorImplTest, EstimateOffset) { EXPECT_LE(true_offset_ms, upper_bound_ms); } -// Same scenario as above, but event C arrives before event B. It doens't mean +// Same scenario as above, but event C arrives before event B. It doesn't mean // event C occurred before event B. TEST_F(ReceiverTimeOffsetEstimatorImplTest, EventCArrivesBeforeEventB) { int64 true_offset_ms = 100; @@ -128,23 +146,29 @@ TEST_F(ReceiverTimeOffsetEstimatorImplTest, EventCArrivesBeforeEventB) { AdvanceClocks(base::TimeDelta::FromMilliseconds(20)); - cast_environment_->Logging()->InsertEncodedFrameEvent( - sender_clock_->NowTicks(), - FRAME_ENCODED, VIDEO_EVENT, - rtp_timestamp, - frame_id, - 1234, - true, - 5678, - 9.10, - 11.12); - - cast_environment_->Logging()->InsertPacketEvent( - sender_clock_->NowTicks(), - PACKET_SENT_TO_NETWORK, VIDEO_EVENT, - rtp_timestamp, - frame_id, - 56, 78, 1500); + scoped_ptr<FrameEvent> encode_event(new FrameEvent()); + encode_event->timestamp = sender_clock_->NowTicks(); + encode_event->type = FRAME_ENCODED; + encode_event->media_type = VIDEO_EVENT; + encode_event->rtp_timestamp = rtp_timestamp; + encode_event->frame_id = frame_id; + encode_event->size = 1234; + encode_event->key_frame = true; + encode_event->target_bitrate = 5678; + encode_event->encoder_cpu_utilization = 9.10; + encode_event->idealized_bitrate_utilization = 11.12; + cast_environment_->logger()->DispatchFrameEvent(encode_event.Pass()); + + scoped_ptr<PacketEvent> send_event(new PacketEvent()); + send_event->timestamp = sender_clock_->NowTicks(); + send_event->type = PACKET_SENT_TO_NETWORK; + send_event->media_type = VIDEO_EVENT; + send_event->rtp_timestamp = rtp_timestamp; + send_event->frame_id = frame_id; + send_event->packet_id = 56; + send_event->max_packet_id = 78; + send_event->size = 1500; + cast_environment_->logger()->DispatchPacketEvent(send_event.Pass()); EXPECT_FALSE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); @@ -153,20 +177,34 @@ TEST_F(ReceiverTimeOffsetEstimatorImplTest, EventCArrivesBeforeEventB) { AdvanceClocks(base::TimeDelta::FromMilliseconds(30)); base::TimeTicks event_c_time = sender_clock_->NowTicks(); - cast_environment_->Logging()->InsertFrameEvent( - event_c_time, FRAME_ACK_RECEIVED, VIDEO_EVENT, rtp_timestamp, frame_id); + scoped_ptr<FrameEvent> ack_event(new FrameEvent()); + ack_event->timestamp = event_c_time; + ack_event->type = FRAME_ACK_RECEIVED; + ack_event->media_type = VIDEO_EVENT; + ack_event->rtp_timestamp = rtp_timestamp; + ack_event->frame_id = frame_id; + cast_environment_->logger()->DispatchFrameEvent(ack_event.Pass()); EXPECT_FALSE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); - cast_environment_->Logging()->InsertPacketEvent( - event_b_time, - PACKET_RECEIVED, VIDEO_EVENT, - rtp_timestamp, - frame_id, - 56, 78, 1500); - - cast_environment_->Logging()->InsertFrameEvent( - event_b_time, FRAME_ACK_SENT, VIDEO_EVENT, rtp_timestamp, frame_id); + scoped_ptr<PacketEvent> receive_event(new PacketEvent()); + receive_event->timestamp = event_b_time; + receive_event->type = PACKET_RECEIVED; + receive_event->media_type = VIDEO_EVENT; + receive_event->rtp_timestamp = rtp_timestamp; + receive_event->frame_id = frame_id; + receive_event->packet_id = 56; + receive_event->max_packet_id = 78; + receive_event->size = 1500; + cast_environment_->logger()->DispatchPacketEvent(receive_event.Pass()); + + scoped_ptr<FrameEvent> ack_sent_event(new FrameEvent()); + ack_sent_event->timestamp = event_b_time; + ack_sent_event->type = FRAME_ACK_SENT; + ack_sent_event->media_type = VIDEO_EVENT; + ack_sent_event->rtp_timestamp = rtp_timestamp; + ack_sent_event->frame_id = frame_id; + cast_environment_->logger()->DispatchFrameEvent(ack_sent_event.Pass()); EXPECT_TRUE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); @@ -198,111 +236,155 @@ TEST_F(ReceiverTimeOffsetEstimatorImplTest, MultipleIterations) { // Bound should end up at [95, 103] // Events times in chronological order: 20, 30 x2, 50, 55, 60, 77, 80, 110 AdvanceClocks(base::TimeDelta::FromMilliseconds(20)); - cast_environment_->Logging()->InsertEncodedFrameEvent( - sender_clock_->NowTicks(), - FRAME_ENCODED, VIDEO_EVENT, - rtp_timestamp_a, - frame_id_a, - 1234, - true, - 5678, - 9.10, - 11.12); - - cast_environment_->Logging()->InsertPacketEvent( - sender_clock_->NowTicks(), - PACKET_SENT_TO_NETWORK, VIDEO_EVENT, - rtp_timestamp_a, - frame_id_a, - 56, 78, 1500); + scoped_ptr<FrameEvent> encode_event(new FrameEvent()); + encode_event->timestamp = sender_clock_->NowTicks(); + encode_event->type = FRAME_ENCODED; + encode_event->media_type = VIDEO_EVENT; + encode_event->rtp_timestamp = rtp_timestamp_a; + encode_event->frame_id = frame_id_a; + encode_event->size = 1234; + encode_event->key_frame = true; + encode_event->target_bitrate = 5678; + encode_event->encoder_cpu_utilization = 9.10; + encode_event->idealized_bitrate_utilization = 11.12; + cast_environment_->logger()->DispatchFrameEvent(encode_event.Pass()); + + scoped_ptr<PacketEvent> send_event(new PacketEvent()); + send_event->timestamp = sender_clock_->NowTicks(); + send_event->type = PACKET_SENT_TO_NETWORK; + send_event->media_type = VIDEO_EVENT; + send_event->rtp_timestamp = rtp_timestamp_a; + send_event->frame_id = frame_id_a; + send_event->packet_id = 56; + send_event->max_packet_id = 78; + send_event->size = 1500; + cast_environment_->logger()->DispatchPacketEvent(send_event.Pass()); AdvanceClocks(base::TimeDelta::FromMilliseconds(10)); - cast_environment_->Logging()->InsertEncodedFrameEvent( - sender_clock_->NowTicks(), - FRAME_ENCODED, VIDEO_EVENT, - rtp_timestamp_b, - frame_id_b, - 1234, - true, - 5678, - 9.10, - 11.12); - - cast_environment_->Logging()->InsertPacketEvent( - sender_clock_->NowTicks(), - PACKET_SENT_TO_NETWORK, VIDEO_EVENT, - rtp_timestamp_b, - frame_id_b, - 56, 78, 1500); - - cast_environment_->Logging()->InsertFrameEvent( - receiver_clock_.NowTicks(), FRAME_ACK_SENT, VIDEO_EVENT, - rtp_timestamp_a, frame_id_a); + encode_event.reset(new FrameEvent()); + encode_event->timestamp = sender_clock_->NowTicks(); + encode_event->type = FRAME_ENCODED; + encode_event->media_type = VIDEO_EVENT; + encode_event->rtp_timestamp = rtp_timestamp_b; + encode_event->frame_id = frame_id_b; + encode_event->size = 1234; + encode_event->key_frame = true; + encode_event->target_bitrate = 5678; + encode_event->encoder_cpu_utilization = 9.10; + encode_event->idealized_bitrate_utilization = 11.12; + cast_environment_->logger()->DispatchFrameEvent(encode_event.Pass()); + + send_event.reset(new PacketEvent()); + send_event->timestamp = sender_clock_->NowTicks(); + send_event->type = PACKET_SENT_TO_NETWORK; + send_event->media_type = VIDEO_EVENT; + send_event->rtp_timestamp = rtp_timestamp_b; + send_event->frame_id = frame_id_b; + send_event->packet_id = 56; + send_event->max_packet_id = 78; + send_event->size = 1500; + cast_environment_->logger()->DispatchPacketEvent(send_event.Pass()); + + scoped_ptr<FrameEvent> ack_sent_event(new FrameEvent()); + ack_sent_event->timestamp = receiver_clock_.NowTicks(); + ack_sent_event->type = FRAME_ACK_SENT; + ack_sent_event->media_type = VIDEO_EVENT; + ack_sent_event->rtp_timestamp = rtp_timestamp_a; + ack_sent_event->frame_id = frame_id_a; + cast_environment_->logger()->DispatchFrameEvent(ack_sent_event.Pass()); AdvanceClocks(base::TimeDelta::FromMilliseconds(20)); - cast_environment_->Logging()->InsertPacketEvent( - receiver_clock_.NowTicks(), - PACKET_RECEIVED, VIDEO_EVENT, - rtp_timestamp_b, - frame_id_b, - 56, 78, 1500); - - cast_environment_->Logging()->InsertFrameEvent( - receiver_clock_.NowTicks(), FRAME_ACK_SENT, VIDEO_EVENT, - rtp_timestamp_b, frame_id_b); + scoped_ptr<PacketEvent> receive_event(new PacketEvent()); + receive_event->timestamp = receiver_clock_.NowTicks(); + receive_event->type = PACKET_RECEIVED; + receive_event->media_type = VIDEO_EVENT; + receive_event->rtp_timestamp = rtp_timestamp_b; + receive_event->frame_id = frame_id_b; + receive_event->packet_id = 56; + receive_event->max_packet_id = 78; + receive_event->size = 1500; + cast_environment_->logger()->DispatchPacketEvent(receive_event.Pass()); + + ack_sent_event.reset(new FrameEvent()); + ack_sent_event->timestamp = receiver_clock_.NowTicks(); + ack_sent_event->type = FRAME_ACK_SENT; + ack_sent_event->media_type = VIDEO_EVENT; + ack_sent_event->rtp_timestamp = rtp_timestamp_b; + ack_sent_event->frame_id = frame_id_b; + cast_environment_->logger()->DispatchFrameEvent(ack_sent_event.Pass()); AdvanceClocks(base::TimeDelta::FromMilliseconds(5)); - cast_environment_->Logging()->InsertFrameEvent(sender_clock_->NowTicks(), - FRAME_ACK_RECEIVED, - VIDEO_EVENT, - rtp_timestamp_b, - frame_id_b); + scoped_ptr<FrameEvent> ack_event(new FrameEvent()); + ack_event->timestamp = sender_clock_->NowTicks(); + ack_event->type = FRAME_ACK_RECEIVED; + ack_event->media_type = VIDEO_EVENT; + ack_event->rtp_timestamp = rtp_timestamp_b; + ack_event->frame_id = frame_id_b; + cast_environment_->logger()->DispatchFrameEvent(ack_event.Pass()); AdvanceClocks(base::TimeDelta::FromMilliseconds(5)); - cast_environment_->Logging()->InsertFrameEvent(sender_clock_->NowTicks(), - FRAME_ACK_RECEIVED, - VIDEO_EVENT, - rtp_timestamp_a, - frame_id_a); + ack_event.reset(new FrameEvent()); + ack_event->timestamp = sender_clock_->NowTicks(); + ack_event->type = FRAME_ACK_RECEIVED; + ack_event->media_type = VIDEO_EVENT; + ack_event->rtp_timestamp = rtp_timestamp_a; + ack_event->frame_id = frame_id_a; + cast_environment_->logger()->DispatchFrameEvent(ack_event.Pass()); AdvanceClocks(base::TimeDelta::FromMilliseconds(17)); - cast_environment_->Logging()->InsertEncodedFrameEvent( - sender_clock_->NowTicks(), - FRAME_ENCODED, VIDEO_EVENT, - rtp_timestamp_c, - frame_id_c, - 1234, - true, - 5678, - 9.10, - 11.12); - - cast_environment_->Logging()->InsertPacketEvent( - sender_clock_->NowTicks(), - PACKET_SENT_TO_NETWORK, VIDEO_EVENT, - rtp_timestamp_c, - frame_id_c, - 56, 78, 1500); + encode_event.reset(new FrameEvent()); + encode_event->timestamp = sender_clock_->NowTicks(); + encode_event->type = FRAME_ENCODED; + encode_event->media_type = VIDEO_EVENT; + encode_event->rtp_timestamp = rtp_timestamp_c; + encode_event->frame_id = frame_id_c; + encode_event->size = 1234; + encode_event->key_frame = true; + encode_event->target_bitrate = 5678; + encode_event->encoder_cpu_utilization = 9.10; + encode_event->idealized_bitrate_utilization = 11.12; + cast_environment_->logger()->DispatchFrameEvent(encode_event.Pass()); + + send_event.reset(new PacketEvent()); + send_event->timestamp = sender_clock_->NowTicks(); + send_event->type = PACKET_SENT_TO_NETWORK; + send_event->media_type = VIDEO_EVENT; + send_event->rtp_timestamp = rtp_timestamp_c; + send_event->frame_id = frame_id_c; + send_event->packet_id = 56; + send_event->max_packet_id = 78; + send_event->size = 1500; + cast_environment_->logger()->DispatchPacketEvent(send_event.Pass()); AdvanceClocks(base::TimeDelta::FromMilliseconds(3)); - cast_environment_->Logging()->InsertPacketEvent( - receiver_clock_.NowTicks(), - PACKET_RECEIVED, VIDEO_EVENT, - rtp_timestamp_c, - frame_id_c, - 56, 78, 1500); - - cast_environment_->Logging()->InsertFrameEvent( - receiver_clock_.NowTicks(), FRAME_ACK_SENT, VIDEO_EVENT, - rtp_timestamp_c, frame_id_c); + receive_event.reset(new PacketEvent()); + receive_event->timestamp = receiver_clock_.NowTicks(); + receive_event->type = PACKET_RECEIVED; + receive_event->media_type = VIDEO_EVENT; + receive_event->rtp_timestamp = rtp_timestamp_c; + receive_event->frame_id = frame_id_c; + receive_event->packet_id = 56; + receive_event->max_packet_id = 78; + receive_event->size = 1500; + cast_environment_->logger()->DispatchPacketEvent(receive_event.Pass()); + + ack_sent_event.reset(new FrameEvent()); + ack_sent_event->timestamp = receiver_clock_.NowTicks(); + ack_sent_event->type = FRAME_ACK_SENT; + ack_sent_event->media_type = VIDEO_EVENT; + ack_sent_event->rtp_timestamp = rtp_timestamp_c; + ack_sent_event->frame_id = frame_id_c; + cast_environment_->logger()->DispatchFrameEvent(ack_sent_event.Pass()); AdvanceClocks(base::TimeDelta::FromMilliseconds(30)); - cast_environment_->Logging()->InsertFrameEvent(sender_clock_->NowTicks(), - FRAME_ACK_RECEIVED, - VIDEO_EVENT, - rtp_timestamp_c, - frame_id_c); + ack_event.reset(new FrameEvent()); + ack_event->timestamp = sender_clock_->NowTicks(); + ack_event->type = FRAME_ACK_RECEIVED; + ack_event->media_type = VIDEO_EVENT; + ack_event->rtp_timestamp = rtp_timestamp_c; + ack_event->frame_id = frame_id_c; + cast_environment_->logger()->DispatchFrameEvent(ack_event.Pass()); EXPECT_TRUE(estimator_.GetReceiverOffsetBounds(&lower_bound, &upper_bound)); int64 lower_bound_ms = lower_bound.InMilliseconds(); diff --git a/media/cast/logging/simple_event_subscriber_unittest.cc b/media/cast/logging/simple_event_subscriber_unittest.cc index bf2c210..92b6c6e 100644 --- a/media/cast/logging/simple_event_subscriber_unittest.cc +++ b/media/cast/logging/simple_event_subscriber_unittest.cc @@ -25,11 +25,11 @@ class SimpleEventSubscriberTest : public ::testing::Test { task_runner_, task_runner_, task_runner_)) { - cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber_); + cast_environment_->logger()->Subscribe(&event_subscriber_); } ~SimpleEventSubscriberTest() override { - cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber_); + cast_environment_->logger()->Unsubscribe(&event_subscriber_); } base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. @@ -40,32 +40,58 @@ class SimpleEventSubscriberTest : public ::testing::Test { TEST_F(SimpleEventSubscriberTest, GetAndResetEvents) { // Log some frame events. - cast_environment_->Logging()->InsertEncodedFrameEvent( - testing_clock_->NowTicks(), FRAME_ENCODED, AUDIO_EVENT, - /*rtp_timestamp*/ 100u, /*frame_id*/ 0u, /*frame_size*/ 123, - /*key_frame*/ false, 0, 0.01, 0.02); - cast_environment_->Logging()->InsertFrameEventWithDelay( - testing_clock_->NowTicks(), FRAME_PLAYOUT, AUDIO_EVENT, - /*rtp_timestamp*/ 100u, - /*frame_id*/ 0u, /*delay*/ base::TimeDelta::FromMilliseconds(100)); - cast_environment_->Logging()->InsertFrameEvent( - testing_clock_->NowTicks(), FRAME_DECODED, AUDIO_EVENT, - /*rtp_timestamp*/ 200u, - /*frame_id*/ 0u); + scoped_ptr<FrameEvent> encode_event(new FrameEvent()); + encode_event->timestamp = testing_clock_->NowTicks(); + encode_event->type = FRAME_ENCODED; + encode_event->media_type = AUDIO_EVENT; + encode_event->rtp_timestamp = 100u; + encode_event->frame_id = 0u; + encode_event->size = 1234; + encode_event->key_frame = true; + encode_event->target_bitrate = 128u; + encode_event->encoder_cpu_utilization = 0.01; + encode_event->idealized_bitrate_utilization = 0.02; + cast_environment_->logger()->DispatchFrameEvent(encode_event.Pass()); + + scoped_ptr<FrameEvent> playout_event(new FrameEvent()); + playout_event->timestamp = testing_clock_->NowTicks(); + playout_event->type = FRAME_PLAYOUT; + playout_event->media_type = AUDIO_EVENT; + playout_event->rtp_timestamp = 100u; + playout_event->frame_id = 0u; + playout_event->delay_delta = base::TimeDelta::FromMilliseconds(100); + cast_environment_->logger()->DispatchFrameEvent(playout_event.Pass()); + + scoped_ptr<FrameEvent> decode_event(new FrameEvent()); + decode_event->timestamp = testing_clock_->NowTicks(); + decode_event->type = FRAME_DECODED; + decode_event->media_type = AUDIO_EVENT; + decode_event->rtp_timestamp = 200u; + decode_event->frame_id = 0u; + cast_environment_->logger()->DispatchFrameEvent(decode_event.Pass()); // Log some packet events. - cast_environment_->Logging()->InsertPacketEvent( - testing_clock_->NowTicks(), PACKET_RECEIVED, AUDIO_EVENT, - /*rtp_timestamp*/ 200u, - /*frame_id*/ 0u, /*packet_id*/ 1u, /*max_packet_id*/ 5u, /*size*/ 100u); - cast_environment_->Logging()->InsertPacketEvent( - testing_clock_->NowTicks(), FRAME_DECODED, VIDEO_EVENT, - /*rtp_timestamp*/ 200u, /*frame_id*/ 0u, /*packet_id*/ 1u, - /*max_packet_id*/ 5u, /*size*/ 100u); - cast_environment_->Logging()->InsertPacketEvent( - testing_clock_->NowTicks(), FRAME_DECODED, VIDEO_EVENT, - /*rtp_timestamp*/ 300u, /*frame_id*/ 0u, /*packet_id*/ 1u, - /*max_packet_id*/ 5u, /*size*/ 100u); + scoped_ptr<PacketEvent> receive_event(new PacketEvent()); + receive_event->timestamp = testing_clock_->NowTicks(); + receive_event->type = PACKET_RECEIVED; + receive_event->media_type = AUDIO_EVENT; + receive_event->rtp_timestamp = 200u; + receive_event->frame_id = 0u; + receive_event->packet_id = 1u; + receive_event->max_packet_id = 5u; + receive_event->size = 100u; + cast_environment_->logger()->DispatchPacketEvent(receive_event.Pass()); + + receive_event.reset(new PacketEvent()); + receive_event->timestamp = testing_clock_->NowTicks(); + receive_event->type = PACKET_RECEIVED; + receive_event->media_type = VIDEO_EVENT; + receive_event->rtp_timestamp = 200u; + receive_event->frame_id = 0u; + receive_event->packet_id = 1u; + receive_event->max_packet_id = 10u; + receive_event->size = 1024u; + cast_environment_->logger()->DispatchPacketEvent(receive_event.Pass()); std::vector<FrameEvent> frame_events; event_subscriber_.GetFrameEventsAndReset(&frame_events); @@ -73,7 +99,7 @@ TEST_F(SimpleEventSubscriberTest, GetAndResetEvents) { std::vector<PacketEvent> packet_events; event_subscriber_.GetPacketEventsAndReset(&packet_events); - EXPECT_EQ(3u, packet_events.size()); + EXPECT_EQ(2u, packet_events.size()); // Calling this function again should result in empty vector because no events // were logged since last call. diff --git a/media/cast/logging/stats_event_subscriber_unittest.cc b/media/cast/logging/stats_event_subscriber_unittest.cc index 09dc517..d649c89 100644 --- a/media/cast/logging/stats_event_subscriber_unittest.cc +++ b/media/cast/logging/stats_event_subscriber_unittest.cc @@ -35,19 +35,17 @@ class StatsEventSubscriberTest : public ::testing::Test { fake_offset_estimator_( base::TimeDelta::FromSeconds(kReceiverOffsetSecs)) { receiver_clock_.Advance(base::TimeDelta::FromSeconds(kReceiverOffsetSecs)); - cast_environment_->Logging()->AddRawEventSubscriber( - &fake_offset_estimator_); + cast_environment_->logger()->Subscribe(&fake_offset_estimator_); } ~StatsEventSubscriberTest() override { if (subscriber_.get()) - cast_environment_->Logging()->RemoveRawEventSubscriber(subscriber_.get()); - cast_environment_->Logging()->RemoveRawEventSubscriber( - &fake_offset_estimator_); + cast_environment_->logger()->Unsubscribe(subscriber_.get()); + cast_environment_->logger()->Unsubscribe(&fake_offset_estimator_); } void AdvanceClocks(base::TimeDelta delta) { - sender_clock_->Advance(delta); + task_runner_->Sleep(delta); receiver_clock_.Advance(delta); } @@ -55,7 +53,7 @@ class StatsEventSubscriberTest : public ::testing::Test { DCHECK(!subscriber_.get()); subscriber_.reset(new StatsEventSubscriber( event_media_type, cast_environment_->Clock(), &fake_offset_estimator_)); - cast_environment_->Logging()->AddRawEventSubscriber(subscriber_.get()); + cast_environment_->logger()->Subscribe(subscriber_.get()); } base::SimpleTestTickClock* sender_clock_; // Owned by CastEnvironment. @@ -79,30 +77,35 @@ TEST_F(StatsEventSubscriberTest, CaptureEncode) { base::TimeTicks start_time = sender_clock_->NowTicks(); // Drop half the frames during the encode step. for (int i = 0; i < num_frames; i++) { - cast_environment_->Logging()->InsertFrameEvent(sender_clock_->NowTicks(), - FRAME_CAPTURE_BEGIN, - VIDEO_EVENT, - rtp_timestamp, - frame_id); + scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent()); + capture_begin_event->timestamp = sender_clock_->NowTicks(); + capture_begin_event->type = FRAME_CAPTURE_BEGIN; + capture_begin_event->media_type = VIDEO_EVENT; + capture_begin_event->rtp_timestamp = rtp_timestamp; + cast_environment_->logger()->DispatchFrameEvent(capture_begin_event.Pass()); + AdvanceClocks(base::TimeDelta::FromMicroseconds(10)); - cast_environment_->Logging()->InsertFrameEvent(sender_clock_->NowTicks(), - FRAME_CAPTURE_END, - VIDEO_EVENT, - rtp_timestamp, - frame_id); + scoped_ptr<FrameEvent> capture_end_event(new FrameEvent()); + capture_end_event->timestamp = sender_clock_->NowTicks(); + capture_end_event->type = FRAME_CAPTURE_END; + capture_end_event->media_type = VIDEO_EVENT; + capture_end_event->rtp_timestamp = rtp_timestamp; + cast_environment_->logger()->DispatchFrameEvent(capture_end_event.Pass()); + if (i % 2 == 0) { AdvanceClocks(base::TimeDelta::FromMicroseconds(10)); - cast_environment_->Logging()->InsertEncodedFrameEvent( - sender_clock_->NowTicks(), - FRAME_ENCODED, - VIDEO_EVENT, - rtp_timestamp, - frame_id, - 1024, - true, - 5678, - 9.10, - 11.12); + scoped_ptr<FrameEvent> encode_event(new FrameEvent()); + encode_event->timestamp = sender_clock_->NowTicks(); + encode_event->type = FRAME_ENCODED; + encode_event->media_type = VIDEO_EVENT; + encode_event->rtp_timestamp = rtp_timestamp; + encode_event->frame_id = frame_id; + encode_event->size = 1024; + encode_event->key_frame = true; + encode_event->target_bitrate = 5678; + encode_event->encoder_cpu_utilization = 9.10; + encode_event->idealized_bitrate_utilization = 11.12; + cast_environment_->logger()->DispatchFrameEvent(encode_event.Pass()); } else if (i < extra_frames) { dropped_frames++; } @@ -155,16 +158,18 @@ TEST_F(StatsEventSubscriberTest, Encode) { for (int i = 0; i < num_frames; i++) { int size = 1000 + base::RandInt(-100, 100); total_size += size; - cast_environment_->Logging()->InsertEncodedFrameEvent( - sender_clock_->NowTicks(), - FRAME_ENCODED, VIDEO_EVENT, - rtp_timestamp, - frame_id, - size, - true, - 5678, - 9.10, - 11.12); + scoped_ptr<FrameEvent> encode_event(new FrameEvent()); + encode_event->timestamp = sender_clock_->NowTicks(); + encode_event->type = FRAME_ENCODED; + encode_event->media_type = VIDEO_EVENT; + encode_event->rtp_timestamp = rtp_timestamp; + encode_event->frame_id = frame_id; + encode_event->size = size; + encode_event->key_frame = true; + encode_event->target_bitrate = 5678; + encode_event->encoder_cpu_utilization = 9.10; + encode_event->idealized_bitrate_utilization = 11.12; + cast_environment_->logger()->DispatchFrameEvent(encode_event.Pass()); last_event_time = sender_clock_->NowTicks(); AdvanceClocks(base::TimeDelta::FromMicroseconds(35678)); @@ -215,10 +220,13 @@ TEST_F(StatsEventSubscriberTest, Decode) { int num_frames = 10; base::TimeTicks start_time = sender_clock_->NowTicks(); for (int i = 0; i < num_frames; i++) { - cast_environment_->Logging()->InsertFrameEvent(receiver_clock_.NowTicks(), - FRAME_DECODED, VIDEO_EVENT, - rtp_timestamp, - frame_id); + scoped_ptr<FrameEvent> decode_event(new FrameEvent()); + decode_event->timestamp = receiver_clock_.NowTicks(); + decode_event->type = FRAME_DECODED; + decode_event->media_type = VIDEO_EVENT; + decode_event->rtp_timestamp = rtp_timestamp; + decode_event->frame_id = frame_id; + cast_environment_->logger()->DispatchFrameEvent(decode_event.Pass()); AdvanceClocks(base::TimeDelta::FromMicroseconds(36789)); rtp_timestamp += 90; @@ -251,13 +259,14 @@ TEST_F(StatsEventSubscriberTest, PlayoutDelay) { base::TimeDelta delay = base::TimeDelta::FromMilliseconds(delay_ms); if (delay_ms > 0) late_frames++; - cast_environment_->Logging()->InsertFrameEventWithDelay( - receiver_clock_.NowTicks(), - FRAME_PLAYOUT, - VIDEO_EVENT, - rtp_timestamp, - frame_id, - delay); + scoped_ptr<FrameEvent> playout_event(new FrameEvent()); + playout_event->timestamp = receiver_clock_.NowTicks(); + playout_event->type = FRAME_PLAYOUT; + playout_event->media_type = VIDEO_EVENT; + playout_event->rtp_timestamp = rtp_timestamp; + playout_event->frame_id = frame_id; + playout_event->delay_delta = delay; + cast_environment_->logger()->DispatchFrameEvent(playout_event.Pass()); AdvanceClocks(base::TimeDelta::FromMicroseconds(37890)); rtp_timestamp += 90; @@ -282,11 +291,12 @@ TEST_F(StatsEventSubscriberTest, E2ELatency) { int num_frames = 10; base::TimeDelta total_latency; for (int i = 0; i < num_frames; i++) { - cast_environment_->Logging()->InsertFrameEvent(sender_clock_->NowTicks(), - FRAME_CAPTURE_BEGIN, - VIDEO_EVENT, - rtp_timestamp, - frame_id); + scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent()); + capture_begin_event->timestamp = sender_clock_->NowTicks(); + capture_begin_event->type = FRAME_CAPTURE_BEGIN; + capture_begin_event->media_type = VIDEO_EVENT; + capture_begin_event->rtp_timestamp = rtp_timestamp; + cast_environment_->logger()->DispatchFrameEvent(capture_begin_event.Pass()); int latency_micros = 100000 + base::RandInt(-5000, 50000); base::TimeDelta latency = base::TimeDelta::FromMicroseconds(latency_micros); @@ -296,13 +306,14 @@ TEST_F(StatsEventSubscriberTest, E2ELatency) { base::TimeDelta delay = base::TimeDelta::FromMilliseconds(delay_micros); total_latency += latency; - cast_environment_->Logging()->InsertFrameEventWithDelay( - receiver_clock_.NowTicks(), - FRAME_PLAYOUT, - VIDEO_EVENT, - rtp_timestamp, - frame_id, - delay); + scoped_ptr<FrameEvent> playout_event(new FrameEvent()); + playout_event->timestamp = receiver_clock_.NowTicks(); + playout_event->type = FRAME_PLAYOUT; + playout_event->media_type = VIDEO_EVENT; + playout_event->rtp_timestamp = rtp_timestamp; + playout_event->frame_id = frame_id; + playout_event->delay_delta = delay; + cast_environment_->logger()->DispatchFrameEvent(playout_event.Pass()); rtp_timestamp += 90; frame_id++; @@ -338,11 +349,13 @@ TEST_F(StatsEventSubscriberTest, Packets) { base::TimeTicks sender_encoded_time = sender_clock_->NowTicks(); base::TimeTicks receiver_encoded_time = receiver_clock_.NowTicks(); - cast_environment_->Logging()->InsertFrameEvent(sender_encoded_time, - FRAME_ENCODED, - VIDEO_EVENT, - rtp_timestamp, - 0); + scoped_ptr<FrameEvent> encode_event(new FrameEvent()); + encode_event->timestamp = sender_encoded_time; + encode_event->type = FRAME_ENCODED; + encode_event->media_type = VIDEO_EVENT; + encode_event->rtp_timestamp = rtp_timestamp; + encode_event->frame_id = 0; + cast_environment_->logger()->DispatchFrameEvent(encode_event.Pass()); // Every 2nd packet will be retransmitted once. // Every 4th packet will be retransmitted twice. @@ -351,14 +364,17 @@ TEST_F(StatsEventSubscriberTest, Packets) { int size = 1000 + base::RandInt(-100, 100); total_size += size; - cast_environment_->Logging()->InsertPacketEvent(sender_clock_->NowTicks(), - PACKET_SENT_TO_NETWORK, - VIDEO_EVENT, - rtp_timestamp, - 0, - i, - num_packets - 1, - size); + scoped_ptr<PacketEvent> send_event(new PacketEvent()); + send_event->timestamp = sender_clock_->NowTicks(); + send_event->type = PACKET_SENT_TO_NETWORK; + send_event->media_type = VIDEO_EVENT; + send_event->rtp_timestamp = rtp_timestamp; + send_event->frame_id = 0; + send_event->packet_id = i; + send_event->max_packet_id = num_packets - 1; + send_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(send_event.Pass()); + num_packets_transmitted++; total_queueing_latency += sender_clock_->NowTicks() - sender_encoded_time; @@ -379,15 +395,17 @@ TEST_F(StatsEventSubscriberTest, Packets) { // Retransmission 1. AdvanceClocks(base::TimeDelta::FromMicroseconds(12345)); if (i % 2 == 0) { - cast_environment_->Logging()->InsertPacketEvent( - receiver_clock_.NowTicks(), - PACKET_RETRANSMITTED, - VIDEO_EVENT, - rtp_timestamp, - 0, - i, - num_packets - 1, - size); + scoped_ptr<PacketEvent> retransmit_event(new PacketEvent()); + retransmit_event->timestamp = receiver_clock_.NowTicks(); + retransmit_event->type = PACKET_RETRANSMITTED; + retransmit_event->media_type = VIDEO_EVENT; + retransmit_event->rtp_timestamp = rtp_timestamp; + retransmit_event->frame_id = 0; + retransmit_event->packet_id = i; + retransmit_event->max_packet_id = num_packets - 1; + retransmit_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(retransmit_event.Pass()); + retransmit_total_size += size; num_packets_transmitted++; num_packets_retransmitted++; @@ -396,15 +414,17 @@ TEST_F(StatsEventSubscriberTest, Packets) { // Retransmission 2. AdvanceClocks(base::TimeDelta::FromMicroseconds(13456)); if (i % 4 == 0) { - cast_environment_->Logging()->InsertPacketEvent( - receiver_clock_.NowTicks(), - PACKET_RETRANSMITTED, - VIDEO_EVENT, - rtp_timestamp, - 0, - i, - num_packets - 1, - size); + scoped_ptr<PacketEvent> retransmit_event(new PacketEvent()); + retransmit_event->timestamp = receiver_clock_.NowTicks(); + retransmit_event->type = PACKET_RETRANSMITTED; + retransmit_event->media_type = VIDEO_EVENT; + retransmit_event->rtp_timestamp = rtp_timestamp; + retransmit_event->frame_id = 0; + retransmit_event->packet_id = i; + retransmit_event->max_packet_id = num_packets - 1; + retransmit_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(retransmit_event.Pass()); + retransmit_total_size += size; num_packets_transmitted++; num_packets_retransmitted++; @@ -413,38 +433,45 @@ TEST_F(StatsEventSubscriberTest, Packets) { // Retransmission 3. AdvanceClocks(base::TimeDelta::FromMicroseconds(14567)); if (i % 8 == 0) { - cast_environment_->Logging()->InsertPacketEvent( - receiver_clock_.NowTicks(), - PACKET_RETRANSMITTED, - VIDEO_EVENT, - rtp_timestamp, - 0, - i, - num_packets - 1, - size); - cast_environment_->Logging()->InsertPacketEvent( - receiver_clock_.NowTicks(), - PACKET_RTX_REJECTED, - VIDEO_EVENT, - rtp_timestamp, - 0, - i, - num_packets - 1, - size); + scoped_ptr<PacketEvent> retransmit_event(new PacketEvent()); + retransmit_event->timestamp = receiver_clock_.NowTicks(); + retransmit_event->type = PACKET_RETRANSMITTED; + retransmit_event->media_type = VIDEO_EVENT; + retransmit_event->rtp_timestamp = rtp_timestamp; + retransmit_event->frame_id = 0; + retransmit_event->packet_id = i; + retransmit_event->max_packet_id = num_packets - 1; + retransmit_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(retransmit_event.Pass()); + + scoped_ptr<PacketEvent> reject_event(new PacketEvent()); + reject_event->timestamp = receiver_clock_.NowTicks(); + reject_event->type = PACKET_RTX_REJECTED; + reject_event->media_type = VIDEO_EVENT; + reject_event->rtp_timestamp = rtp_timestamp; + reject_event->frame_id = 0; + reject_event->packet_id = i; + reject_event->max_packet_id = num_packets - 1; + reject_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(reject_event.Pass()); + retransmit_total_size += size; num_packets_transmitted++; num_packets_retransmitted++; num_packets_rtx_rejected++; } - cast_environment_->Logging()->InsertPacketEvent(received_time, - PACKET_RECEIVED, - VIDEO_EVENT, - rtp_timestamp, - 0, - i, - num_packets - 1, - size); + scoped_ptr<PacketEvent> receive_event(new PacketEvent()); + receive_event->timestamp = received_time; + receive_event->type = PACKET_RECEIVED; + receive_event->media_type = VIDEO_EVENT; + receive_event->rtp_timestamp = rtp_timestamp; + receive_event->frame_id = 0; + receive_event->packet_id = i; + receive_event->max_packet_id = num_packets - 1; + receive_event->size = size; + cast_environment_->logger()->DispatchPacketEvent(receive_event.Pass()); + num_packets_received++; } @@ -538,43 +565,51 @@ TEST_F(StatsEventSubscriberTest, Histograms) { for (int i = 0; i < 10; ++i) { ++frame_id; ++rtp_timestamp; - cast_environment_->Logging()->InsertFrameEvent(sender_clock_->NowTicks(), - FRAME_CAPTURE_BEGIN, - VIDEO_EVENT, - rtp_timestamp, - frame_id); + + scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent()); + capture_begin_event->timestamp = sender_clock_->NowTicks(); + capture_begin_event->type = FRAME_CAPTURE_BEGIN; + capture_begin_event->media_type = VIDEO_EVENT; + capture_begin_event->rtp_timestamp = rtp_timestamp; + cast_environment_->logger()->DispatchFrameEvent(capture_begin_event.Pass()); + AdvanceClocks(base::TimeDelta::FromMilliseconds(10)); - cast_environment_->Logging()->InsertFrameEvent(sender_clock_->NowTicks(), - FRAME_CAPTURE_END, - VIDEO_EVENT, - rtp_timestamp, - frame_id); + scoped_ptr<FrameEvent> capture_end_event(new FrameEvent()); + capture_end_event->timestamp = sender_clock_->NowTicks(); + capture_end_event->type = FRAME_CAPTURE_END; + capture_end_event->media_type = VIDEO_EVENT; + capture_end_event->rtp_timestamp = rtp_timestamp; + cast_environment_->logger()->DispatchFrameEvent(capture_end_event.Pass()); + AdvanceClocks(base::TimeDelta::FromMilliseconds(15)); - cast_environment_->Logging()->InsertEncodedFrameEvent( - sender_clock_->NowTicks(), - FRAME_ENCODED, - VIDEO_EVENT, - rtp_timestamp, - frame_id, - 1024, - true, - 5678, - 9.10, - 11.12); + scoped_ptr<FrameEvent> encode_event(new FrameEvent()); + encode_event->timestamp = sender_clock_->NowTicks(); + encode_event->type = FRAME_ENCODED; + encode_event->media_type = VIDEO_EVENT; + encode_event->rtp_timestamp = rtp_timestamp; + encode_event->frame_id = frame_id; + encode_event->size = 1024; + encode_event->key_frame = true; + encode_event->target_bitrate = 5678; + encode_event->encoder_cpu_utilization = 9.10; + encode_event->idealized_bitrate_utilization = 11.12; + cast_environment_->logger()->DispatchFrameEvent(encode_event.Pass()); } // Send 3 packets for the last frame. // Queueing latencies are 100ms, 200ms and 300ms. for (int i = 0; i < 3; ++i) { AdvanceClocks(base::TimeDelta::FromMilliseconds(100)); - cast_environment_->Logging()->InsertPacketEvent(sender_clock_->NowTicks(), - PACKET_SENT_TO_NETWORK, - VIDEO_EVENT, - rtp_timestamp, - 0, - i, - 2, - 123); + scoped_ptr<PacketEvent> send_event(new PacketEvent()); + send_event->timestamp = sender_clock_->NowTicks(); + send_event->type = PACKET_SENT_TO_NETWORK; + send_event->media_type = VIDEO_EVENT; + send_event->rtp_timestamp = rtp_timestamp; + send_event->frame_id = 0; + send_event->packet_id = i; + send_event->max_packet_id = 2; + send_event->size = 123; + cast_environment_->logger()->DispatchPacketEvent(send_event.Pass()); } // Receive 3 packets for the last frame. @@ -582,23 +617,26 @@ TEST_F(StatsEventSubscriberTest, Histograms) { // Packet latencies are 400ms. AdvanceClocks(base::TimeDelta::FromMilliseconds(100)); for (int i = 0; i < 3; ++i) { - cast_environment_->Logging()->InsertPacketEvent(receiver_clock_.NowTicks(), - PACKET_RECEIVED, - VIDEO_EVENT, - rtp_timestamp, - 0, - i, - 2, - 123); + scoped_ptr<PacketEvent> receive_event(new PacketEvent()); + receive_event->timestamp = receiver_clock_.NowTicks(); + receive_event->type = PACKET_RECEIVED; + receive_event->media_type = VIDEO_EVENT; + receive_event->rtp_timestamp = rtp_timestamp; + receive_event->frame_id = 0; + receive_event->packet_id = i; + receive_event->max_packet_id = 2; + receive_event->size = 123; + cast_environment_->logger()->DispatchPacketEvent(receive_event.Pass()); } - cast_environment_->Logging()->InsertFrameEventWithDelay( - receiver_clock_.NowTicks(), - FRAME_PLAYOUT, - VIDEO_EVENT, - rtp_timestamp, - frame_id, - base::TimeDelta::FromMilliseconds(100)); + scoped_ptr<FrameEvent> playout_event(new FrameEvent()); + playout_event->timestamp = receiver_clock_.NowTicks(); + playout_event->type = FRAME_PLAYOUT; + playout_event->media_type = VIDEO_EVENT; + playout_event->rtp_timestamp = rtp_timestamp; + playout_event->frame_id = frame_id; + playout_event->delay_delta = base::TimeDelta::FromMilliseconds(100); + cast_environment_->logger()->DispatchFrameEvent(playout_event.Pass()); StatsEventSubscriber::SimpleHistogram* histogram; scoped_ptr<base::ListValue> values; |