Shaka Packager SDK
trick_play_handler.h
1 // Copyright 2017 Google LLC. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_MEDIA_BASE_TRICK_PLAY_HANDLER_H_
8 #define PACKAGER_MEDIA_BASE_TRICK_PLAY_HANDLER_H_
9 
10 #include <list>
11 
12 #include <packager/media/base/media_handler.h>
13 
14 namespace shaka {
15 namespace media {
16 
17 class VideoStreamInfo;
18 
22 // The stream data in trick play streams are not simple duplicates. Some
23 // information get changed (e.g. VideoStreamInfo.trick_play_factor).
25  public:
26  explicit TrickPlayHandler(uint32_t factor);
27 
28  private:
29  TrickPlayHandler(const TrickPlayHandler&) = delete;
30  TrickPlayHandler& operator=(const TrickPlayHandler&) = delete;
31 
32  Status InitializeInternal() override;
33  Status Process(std::unique_ptr<StreamData> stream_data) override;
34  Status OnFlushRequest(size_t input_stream_index) override;
35 
36  Status OnStreamInfo(const StreamInfo& info);
37  Status OnSegmentInfo(std::shared_ptr<const SegmentInfo> info);
38  Status OnMediaSample(const MediaSample& sample);
39  Status OnTrickFrame(const MediaSample& sample);
40 
41  const uint32_t factor_;
42 
43  uint64_t total_frames_ = 0;
44  uint64_t total_key_frames_ = 0;
45  uint64_t total_trick_frames_ = 0;
46 
47  // We cannot just send video info through as we need to calculate the play
48  // rate using the first two trick play frames. This reference should only be
49  // used to update the play back rate before video info is sent downstream.
50  // After getting sent downstream, this should never be used.
51  std::shared_ptr<VideoStreamInfo> video_info_;
52 
53  // We need to track the segment that most recently finished so that we can
54  // extend its duration if there are empty segments.
55  std::shared_ptr<SegmentInfo> previous_segment_;
56 
57  // Since we are dropping frames, the time that those frames would have been
58  // on screen need to be added to the frame before them. Keep a reference to
59  // the most recent trick play frame so that we can grow its duration as we
60  // drop other frames.
61  std::shared_ptr<MediaSample> previous_trick_frame_;
62 
63  // Since we cannot send messages downstream right away, keep a queue of
64  // messages that need to be sent down. At the start, we use this to queue
65  // messages until we can send out |video_info_|. To ensure messages are
66  // kept in order, messages are only dispatched through this queue and never
67  // directly.
68  std::list<std::unique_ptr<StreamData>> delayed_messages_;
69 };
70 
71 } // namespace media
72 } // namespace shaka
73 
74 #endif // PACKAGER_MEDIA_BASE_TRICK_PLAY_HANDLER_H_
Class to hold a media sample.
Definition: media_sample.h:25
Abstract class holds stream information.
Definition: stream_info.h:71
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66