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