1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CAST_STANDALONE_RECEIVER_SDL_VIDEO_PLAYER_H_ 6 #define CAST_STANDALONE_RECEIVER_SDL_VIDEO_PLAYER_H_ 7 8 #include <string> 9 10 #include "cast/standalone_receiver/sdl_player_base.h" 11 #include "cast/streaming/constants.h" 12 13 namespace openscreen { 14 namespace cast { 15 16 // Consumes frames from a Receiver, decodes them, and renders them to a 17 // SDL_Renderer. 18 class SDLVideoPlayer final : public SDLPlayerBase { 19 public: 20 // |error_callback| is run only if a fatal error occurs, at which point the 21 // player has halted and set |error_status()|. 22 SDLVideoPlayer(ClockNowFunctionPtr now_function, 23 TaskRunner* task_runner, 24 Receiver* receiver, 25 VideoCodec codec_name, 26 SDL_Renderer* renderer, 27 std::function<void()> error_callback); 28 29 ~SDLVideoPlayer() final; 30 31 private: 32 // Renders the "blue splash" (if waiting) or "red splash" (on error), or 33 // otherwise re-renders |frame|; scheduling presentation at an "idle FPS" 34 // rate. 35 bool RenderWhileIdle(const SDLPlayerBase::PresentableFrame* frame) final; 36 37 // Uploads the decoded picture in |frame| to a SDL texture and draws it using 38 // the SDL |renderer_|. 39 ErrorOr<Clock::time_point> RenderNextFrame( 40 const SDLPlayerBase::PresentableFrame& frame) final; 41 42 // Makes whatever is currently drawn to the SDL |renderer_| be presented 43 // on-screen. 44 void Present() final; 45 46 // Maps an AVFrame format enum to the SDL equivalent. 47 static uint32_t GetSDLPixelFormat(const AVFrame& picture); 48 49 // The SDL renderer drawn to. 50 SDL_Renderer* const renderer_; 51 52 // The SDL texture to which the current frame's image is uploaded for 53 // accelerated 2D rendering. 54 SDLTextureUniquePtr texture_; 55 }; 56 57 } // namespace cast 58 } // namespace openscreen 59 60 #endif // CAST_STANDALONE_RECEIVER_SDL_VIDEO_PLAYER_H_ 61