#ifndef MEDIA_CAST_LOGGING_ENCODING_EVENT_SUBSCRIBER_H_
#define MEDIA_CAST_LOGGING_ENCODING_EVENT_SUBSCRIBER_H_
#include <map>
#include "base/memory/linked_ptr.h"
#include "base/threading/thread_checker.h"
#include "media/cast/logging/logging_defines.h"
#include "media/cast/logging/proto/raw_events.pb.h"
#include "media/cast/logging/raw_event_subscriber.h"
namespace media {
namespace cast {
typedef std::map<RtpTimestamp,
linked_ptr<media::cast::proto::AggregatedFrameEvent> >
FrameEventMap;
typedef std::map<RtpTimestamp,
linked_ptr<media::cast::proto::AggregatedPacketEvent> >
PacketEventMap;
class EncodingEventSubscriber : public RawEventSubscriber {
public:
EncodingEventSubscriber(EventMediaType event_media_type, size_t max_frames);
virtual ~EncodingEventSubscriber();
virtual void OnReceiveFrameEvent(const FrameEvent& frame_event) OVERRIDE;
virtual void OnReceivePacketEvent(const PacketEvent& packet_event) OVERRIDE;
virtual void OnReceiveGenericEvent(const GenericEvent& generic_event)
OVERRIDE;
void GetEventsAndReset(media::cast::proto::LogMetadata* metadata,
FrameEventMap* frame_events,
PacketEventMap* packet_events);
private:
bool ShouldProcessEvent(CastLoggingEvent event);
void TruncateFrameEventMapIfNeeded();
void TruncatePacketEventMapIfNeeded();
RtpTimestamp GetRelativeRtpTimestamp(RtpTimestamp rtp_timestamp);
void Reset();
const EventMediaType event_media_type_;
const size_t max_frames_;
FrameEventMap frame_event_map_;
PacketEventMap packet_event_map_;
base::ThreadChecker thread_checker_;
bool seen_first_rtp_timestamp_;
RtpTimestamp first_rtp_timestamp_;
DISALLOW_COPY_AND_ASSIGN(EncodingEventSubscriber);
};
}
}
#endif