logging_raw.h revision a02191e04bc25c4935f804f2c080ae28663d096d
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)
270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Inform of new event: three types of events: frame, packets and generic.
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.
38a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  void InsertEncodedFrameEvent(const base::TimeTicks& time_of_event,
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                CastLoggingEvent event, uint32 rtp_timestamp,
40a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                uint32 frame_id, int size, bool key_frame);
410f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
420f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Render/playout delay
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This function is only applicable for the following frame events:
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // kAudioPlayoutDelay, kVideoRenderDelay
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void InsertFrameEventWithDelay(const base::TimeTicks& time_of_event,
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                 CastLoggingEvent event, uint32 rtp_timestamp,
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                 uint32 frame_id, base::TimeDelta delay);
480f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
490f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Insert a packet event.
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void InsertPacketEvent(const base::TimeTicks& time_of_event,
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         CastLoggingEvent event, uint32 rtp_timestamp,
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         uint32 frame_id, uint16 packet_id,
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         uint16 max_packet_id, size_t size);
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Insert a generic event. The interpretation of |value| depends on
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // type of |event|.
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void InsertGenericEvent(const base::TimeTicks& time_of_event,
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                          CastLoggingEvent event, int value);
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Adds |subscriber| so that it will start receiving events on main thread.
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Note that this class does not own |subscriber|.
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // It is a no-op to add a subscriber that already exists.
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void AddSubscriber(RawEventSubscriber* subscriber);
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Removes |subscriber| so that it will stop receiving events.
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Note that this class does NOT own the subscribers. This function MUST be
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // called before |subscriber| is destroyed if it was previously added.
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // It is a no-op to remove a subscriber that doesn't exist.
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void RemoveSubscriber(RawEventSubscriber* subscriber);
700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) private:
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void InsertBaseFrameEvent(const base::TimeTicks& time_of_event,
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                            CastLoggingEvent event, uint32 frame_id,
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                            uint32 rtp_timestamp, base::TimeDelta delay,
75a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                            int size, bool key_frame);
760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // List of subscriber pointers. This class does not own the subscribers.
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::vector<RawEventSubscriber*> subscribers_;
790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(LoggingRaw);
810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)};
820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}  // namespace cast
840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}  // namespace media
850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#endif  // MEDIA_CAST_LOGGING_LOGGING_RAW_H_
87