logging_raw.h revision 0529e5d033099cbfc42635f6f6183833b09dff6e
10f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 20f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 30f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// found in the LICENSE file. 40f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 50f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#ifndef MEDIA_CAST_LOGGING_LOGGING_RAW_H_ 60f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#define MEDIA_CAST_LOGGING_LOGGING_RAW_H_ 70f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 80f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <vector> 90f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/basictypes.h" 110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/memory/linked_ptr.h" 120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/threading/non_thread_safe.h" 130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/time/tick_clock.h" 140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "media/cast/logging/logging_defines.h" 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "media/cast/logging/raw_event_subscriber.h" 160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace media { 180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace cast { 190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// This class is not thread safe, and should only be called from the main 210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// thread. 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class LoggingRaw : public base::NonThreadSafe { 230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) public: 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LoggingRaw(); 250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) ~LoggingRaw(); 260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Inform of new event: two types of events: frame and packet. 280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Frame events can be inserted with different parameters. 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void InsertFrameEvent(const base::TimeTicks& time_of_event, 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CastLoggingEvent event, uint32 rtp_timestamp, 31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) uint32 frame_id); 320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // This function is only applicable for the following frame events: 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // kAudioFrameEncoded, kVideoFrameEncoded 35a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // |size| - Size of encoded frame. 36a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // |key_frame| - Whether the frame is a key frame. This field is only 37a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // applicable for kVideoFrameEncoded event. 380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // |target_bitrate| - The target bitrate of the encoder the time the frame 390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // was encoded. Only applicable for kVideoFrameEncoded event. 40a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch void InsertEncodedFrameEvent(const base::TimeTicks& time_of_event, 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CastLoggingEvent event, uint32 rtp_timestamp, 420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch uint32 frame_id, int size, bool key_frame, 430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch int target_bitrate); 440f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 450f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Render/playout delay 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // This function is only applicable for the following frame events: 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // kAudioPlayoutDelay, kVideoRenderDelay 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void InsertFrameEventWithDelay(const base::TimeTicks& time_of_event, 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CastLoggingEvent event, uint32 rtp_timestamp, 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) uint32 frame_id, base::TimeDelta delay); 510f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Insert a packet event. 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void InsertPacketEvent(const base::TimeTicks& time_of_event, 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CastLoggingEvent event, uint32 rtp_timestamp, 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) uint32 frame_id, uint16 packet_id, 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) uint16 max_packet_id, size_t size); 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Adds |subscriber| so that it will start receiving events on main thread. 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Note that this class does not own |subscriber|. 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // It is a no-op to add a subscriber that already exists. 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void AddSubscriber(RawEventSubscriber* subscriber); 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Removes |subscriber| so that it will stop receiving events. 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Note that this class does NOT own the subscribers. This function MUST be 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // called before |subscriber| is destroyed if it was previously added. 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // It is a no-op to remove a subscriber that doesn't exist. 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void RemoveSubscriber(RawEventSubscriber* subscriber); 680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) private: 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void InsertBaseFrameEvent(const base::TimeTicks& time_of_event, 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CastLoggingEvent event, uint32 frame_id, 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) uint32 rtp_timestamp, base::TimeDelta delay, 730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch int size, bool key_frame, int target_bitrate); 740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // List of subscriber pointers. This class does not own the subscribers. 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<RawEventSubscriber*> subscribers_; 770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(LoggingRaw); 790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}; 800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} // namespace cast 820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} // namespace media 830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#endif // MEDIA_CAST_LOGGING_LOGGING_RAW_H_ 85