Native Player  1.0
common.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 //
3 // Copyright (c) 2016, Samsung Electronics Co., Ltd
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
20 // , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 //
23 // @author Tomasz Borkowski
24 //
25 // ----------------------------------------------------------------------------
26 
27 #ifndef NATIVE_PLAYER_SRC_COMMON_H_
28 #define NATIVE_PLAYER_SRC_COMMON_H_
29 
30 #include <limits>
31 #include <sstream>
32 #include <string>
33 
34 #include "nacl_player/common.h"
35 
36 #include "dash/media_stream.h"
37 
38 #include "logger.h"
39 
40 #define LOG_STATS __LINE__, __func__, __FILE__
41 #define LOG(msg, ...) Logger::Log(LOG_STATS, msg, ##__VA_ARGS__)
42 #define LOG_ERROR(msg, ...) Logger::Error(LOG_STATS, msg, ##__VA_ARGS__)
43 #define LOG_DEBUG(msg, ...) Logger::Debug(LOG_STATS, msg, ##__VA_ARGS__)
44 
45 template <typename T, class... Args>
46 std::unique_ptr<T> MakeUnique(Args&&... args) {
47  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
48 }
49 
50 template <typename T>
51 std::unique_ptr<T> AdoptUnique(T* ptr) {
52  return std::unique_ptr<T>(ptr);
53 }
54 
55 enum class StreamType : int32_t {
56  Video = static_cast<int32_t>(MediaStreamType::Video),
57  Audio = static_cast<int32_t>(MediaStreamType::Audio),
58  MaxStreamTypes = static_cast<int32_t>(MediaStreamType::MaxTypes)
59 };
60 
61 const Samsung::NaClPlayer::TimeTicks kEndOfStream =
62  std::numeric_limits<Samsung::NaClPlayer::TimeTicks>::infinity();
63 
64 inline std::string ToHexString(uint32_t size, const uint8_t* data) {
65  std::ostringstream oss;
66  oss.setf(std::ios::hex, std::ios::basefield);
67  for (size_t i = 0; i < size; ++i) {
68  oss.width(2);
69  oss.fill('0');
70  oss << static_cast<unsigned>(data[i]);
71  oss << " ";
72  }
73 
74  return oss.str();
75 }
76 
77 #endif // NATIVE_PLAYER_SRC_COMMON_H_
StreamType
Definition: common.h:55
const Samsung::NaClPlayer::TimeTicks kEndOfStream
Definition: common.h:61
This file defines the MediaStreamType enum and CommonStreamDescription, AudioStream, VideoStream structs.
std::string ToHexString(uint32_t size, const uint8_t *data)
Definition: common.h:64
std::unique_ptr< T > AdoptUnique(T *ptr)
Definition: common.h:51
std::unique_ptr< T > MakeUnique(Args &&...args)
Definition: common.h:46