aboutsummaryrefslogtreecommitdiff
path: root/cast/standalone_receiver/sdl_video_player.h
blob: 515649d07bb822763aecc6aea93202aa08f58486 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CAST_STANDALONE_RECEIVER_SDL_VIDEO_PLAYER_H_
#define CAST_STANDALONE_RECEIVER_SDL_VIDEO_PLAYER_H_

#include "cast/standalone_receiver/sdl_player_base.h"

namespace cast {
namespace streaming {

// Consumes frames from a Receiver, decodes them, and renders them to a
// SDL_Renderer.
class SDLVideoPlayer : public SDLPlayerBase {
 public:
  // |error_callback| is run only if a fatal error occurs, at which point the
  // player has halted and set |error_status()|.
  SDLVideoPlayer(openscreen::ClockNowFunctionPtr now_function,
                 openscreen::TaskRunner* task_runner,
                 Receiver* receiver,
                 SDL_Renderer* renderer,
                 std::function<void()> error_callback);

  ~SDLVideoPlayer() final;

 private:
  // Renders the "blue splash" (if waiting) or "red splash" (on error), or
  // otherwise re-renders |frame|; scheduling presentation at an "idle FPS"
  // rate.
  bool RenderWhileIdle(const SDLPlayerBase::PresentableFrame* frame) final;

  // Uploads the decoded picture in |frame| to a SDL texture and draws it using
  // the SDL |renderer_|.
  openscreen::ErrorOr<openscreen::Clock::time_point> RenderNextFrame(
      const SDLPlayerBase::PresentableFrame& frame) final;

  // Makes whatever is currently drawn to the SDL |renderer_| be presented
  // on-screen.
  void Present() final;

  // Maps an AVFrame format enum to the SDL equivalent.
  static uint32_t GetSDLPixelFormat(const AVFrame& picture);

  // The SDL renderer drawn to.
  SDL_Renderer* const renderer_;

  // The SDL texture to which the current frame's image is uploaded for
  // accelerated 2D rendering.
  SDLTextureUniquePtr texture_;
};

}  // namespace streaming
}  // namespace cast

#endif  // CAST_STANDALONE_RECEIVER_SDL_VIDEO_PLAYER_H_