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