Tizen WASM Player
Tizen TV WebAssembly Media Player extension allowing for a low-level elementary media stream playback.
elementary_media_stream_source.h
Go to the documentation of this file.
1 // Copyright 2020 Samsung Electronics
2 // TizenTV Emscripten extensions are available under two separate licenses, the
3 // MIT license and the University of Illinois/NCSA Open Source License. Both
4 // these licenses can be found in the LICENSE file.
5 
6 #ifndef INCLUDE_SAMSUNG_WASM_ELEMENTARY_MEDIA_STREAM_SOURCE_H_
7 #define INCLUDE_SAMSUNG_WASM_ELEMENTARY_MEDIA_STREAM_SOURCE_H_
8 
9 #include <cstdlib>
10 #include <functional>
11 #include <memory>
12 #include <string>
13 
14 #include "samsung/wasm/common.h"
17 
18 namespace samsung {
19 
20 namespace html {
21 class HTMLMediaElement;
22 } // namespace html
23 
24 namespace wasm {
25 
26 class ElementaryMediaStreamSourceListener;
27 struct ElementaryAudioTrackConfig;
28 struct ElementaryVideoTrackConfig;
29 
59 
143  public:
147  enum class Mode {
158  kNormal,
159 
176  kLowLatency,
177 
198  kVideoTexture
199  };
200 
218  enum class ReadyState {
222  kDetached,
223 
234  kClosed,
235 
243  kOpenPending,
244 
256  kOpen,
257 
265  kEnded
266  };
267 
272  explicit ElementaryMediaStreamSource(Mode mode = Mode::kNormal);
276  delete;
279 
285  bool IsValid() const;
286 
304 
322  Result<void> AddTrack(
324  std::function<void(OperationResult, ElementaryMediaTrack)>
325  on_finished_callback);
326 
346 
366  Result<void> AddTrack(
368  std::function<void(OperationResult, ElementaryMediaTrack)>
369  on_finished_callback);
370 
382  Result<void> RemoveTrack(const ElementaryMediaTrack&);
383 
390  Result<void> Flush();
391 
404  Result<void> Close(std::function<void(OperationResult)> on_finished_callback);
405 
421  Result<void> Open(std::function<void(OperationResult)> on_finished_callback);
422 
428  Result<Seconds> GetDuration() const;
429 
438  Result<void> SetDuration(Seconds new_duration);
439 
446  Result<Mode> GetMode() const;
447 
454  Result<ReadyState> GetReadyState() const;
455 
470  Result<void> SetListener(ElementaryMediaStreamSourceListener* listener);
471 
478  const char* GetURL() const;
479 
480  private:
481  std::function<void(OperationResult, int32_t handle)> GetOnAddTrackDoneCb(
483  std::function<void(OperationResult, ElementaryMediaTrack)>
484  on_finished_callback);
485  void SetHTMLMediaElement(html::HTMLMediaElement*);
486  OperationResult SetListenerInternal(
488 
489  int handle_;
490  html::HTMLMediaElement* html_media_element_;
492  std::unique_ptr<char, decltype(&std::free)> url_;
493  bool use_session_id_emulation_;
494  EmssVersionInfo version_info_;
495 
497 };
498 
499 } // namespace wasm
500 } // namespace samsung
501 
502 #endif // INCLUDE_SAMSUNG_WASM_ELEMENTARY_MEDIA_STREAM_SOURCE_H_
Main class of WASM Player. ElementaryMediaStreamSource acts as a data source for html::HTMLMediaEleme...
Allows receiving ElementaryMediaStreamSource events.
std::chrono::duration< double > Seconds
Default duration type used throughout the API.
Definition: common.h:53
TrackType
Enumerates track types. Can be obtained by GetType().
OperationResult
Enumerates possible outcomes of WASM function calls.
Wraps HTMLMediaElement so that it can be used in WebAssembly code.
Contains audio ElementaryMediaTrack config.
Contains video ElementaryMediaTrack config.
Tracks are used to deliver either audio or video frames to WASM Player.