| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "webrtc/base/basictypes.h" | 35 #include "webrtc/base/basictypes.h" |
| 36 #include "webrtc/base/timeutils.h" | 36 #include "webrtc/base/timeutils.h" |
| 37 | 37 |
| 38 namespace cricket { | 38 namespace cricket { |
| 39 | 39 |
| 40 // TODO(janahan): For now, a hard-coded ssrc is used as the video ssrc. | 40 // TODO(janahan): For now, a hard-coded ssrc is used as the video ssrc. |
| 41 // This is because when the video frame is passed to the mediaprocessor for | 41 // This is because when the video frame is passed to the mediaprocessor for |
| 42 // processing, it doesn't have the correct ssrc. Since currently only Tx | 42 // processing, it doesn't have the correct ssrc. Since currently only Tx |
| 43 // Video processing is supported, this is ok. When we switch over to trigger | 43 // Video processing is supported, this is ok. When we switch over to trigger |
| 44 // from capturer, this should be fixed and this const removed. | 44 // from capturer, this should be fixed and this const removed. |
| 45 const uint32 kDummyVideoSsrc = 0xFFFFFFFF; | 45 const uint32_t kDummyVideoSsrc = 0xFFFFFFFF; |
| 46 | 46 |
| 47 // Minimum interval is 10k fps. | 47 // Minimum interval is 10k fps. |
| 48 #define FPS_TO_INTERVAL(fps) \ | 48 #define FPS_TO_INTERVAL(fps) \ |
| 49 (fps ? rtc::kNumNanosecsPerSec / fps : \ | 49 (fps ? rtc::kNumNanosecsPerSec / fps : \ |
| 50 rtc::kNumNanosecsPerSec / 10000) | 50 rtc::kNumNanosecsPerSec / 10000) |
| 51 | 51 |
| 52 ////////////////////////////////////////////////////////////////////////////// | 52 ////////////////////////////////////////////////////////////////////////////// |
| 53 // Definition of FourCC codes | 53 // Definition of FourCC codes |
| 54 ////////////////////////////////////////////////////////////////////////////// | 54 ////////////////////////////////////////////////////////////////////////////// |
| 55 // Convert four characters to a FourCC code. | 55 // Convert four characters to a FourCC code. |
| 56 // Needs to be a macro otherwise the OS X compiler complains when the kFormat* | 56 // Needs to be a macro otherwise the OS X compiler complains when the kFormat* |
| 57 // constants are used in a switch. | 57 // constants are used in a switch. |
| 58 #define FOURCC(a, b, c, d) ( \ | 58 #define FOURCC(a, b, c, d) \ |
| 59 (static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \ | 59 ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \ |
| 60 (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24)) | 60 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24)) |
| 61 // Some pages discussing FourCC codes: | 61 // Some pages discussing FourCC codes: |
| 62 // http://www.fourcc.org/yuv.php | 62 // http://www.fourcc.org/yuv.php |
| 63 // http://v4l2spec.bytesex.org/spec/book1.htm | 63 // http://v4l2spec.bytesex.org/spec/book1.htm |
| 64 // http://developer.apple.com/quicktime/icefloe/dispatch020.html | 64 // http://developer.apple.com/quicktime/icefloe/dispatch020.html |
| 65 // http://msdn.microsoft.com/library/windows/desktop/dd206750.aspx#nv12 | 65 // http://msdn.microsoft.com/library/windows/desktop/dd206750.aspx#nv12 |
| 66 // http://people.xiph.org/~xiphmont/containers/nut/nut4cc.txt | 66 // http://people.xiph.org/~xiphmont/containers/nut/nut4cc.txt |
| 67 | 67 |
| 68 // FourCC codes grouped according to implementation efficiency. | 68 // FourCC codes grouped according to implementation efficiency. |
| 69 // Primary formats should convert in 1 efficient step. | 69 // Primary formats should convert in 1 efficient step. |
| 70 // Secondary formats are converted in 2 steps. | 70 // Secondary formats are converted in 2 steps. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 130 |
| 131 // 1 Auxiliary compressed YUV format set aside for capturer. | 131 // 1 Auxiliary compressed YUV format set aside for capturer. |
| 132 FOURCC_H264 = FOURCC('H', '2', '6', '4'), | 132 FOURCC_H264 = FOURCC('H', '2', '6', '4'), |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 // Match any fourcc. | 135 // Match any fourcc. |
| 136 | 136 |
| 137 // We move this out of the enum because using it in many places caused | 137 // We move this out of the enum because using it in many places caused |
| 138 // the compiler to get grumpy, presumably since the above enum is | 138 // the compiler to get grumpy, presumably since the above enum is |
| 139 // backed by an int. | 139 // backed by an int. |
| 140 static const uint32 FOURCC_ANY = 0xFFFFFFFF; | 140 static const uint32_t FOURCC_ANY = 0xFFFFFFFF; |
| 141 | 141 |
| 142 // Converts fourcc aliases into canonical ones. | 142 // Converts fourcc aliases into canonical ones. |
| 143 uint32 CanonicalFourCC(uint32 fourcc); | 143 uint32_t CanonicalFourCC(uint32_t fourcc); |
| 144 | 144 |
| 145 // Get FourCC code as a string. | 145 // Get FourCC code as a string. |
| 146 inline std::string GetFourccName(uint32 fourcc) { | 146 inline std::string GetFourccName(uint32_t fourcc) { |
| 147 std::string name; | 147 std::string name; |
| 148 name.push_back(static_cast<char>(fourcc & 0xFF)); | 148 name.push_back(static_cast<char>(fourcc & 0xFF)); |
| 149 name.push_back(static_cast<char>((fourcc >> 8) & 0xFF)); | 149 name.push_back(static_cast<char>((fourcc >> 8) & 0xFF)); |
| 150 name.push_back(static_cast<char>((fourcc >> 16) & 0xFF)); | 150 name.push_back(static_cast<char>((fourcc >> 16) & 0xFF)); |
| 151 name.push_back(static_cast<char>((fourcc >> 24) & 0xFF)); | 151 name.push_back(static_cast<char>((fourcc >> 24) & 0xFF)); |
| 152 return name; | 152 return name; |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Computes a scale less to fit in max_pixels while maintaining aspect ratio. | 155 // Computes a scale less to fit in max_pixels while maintaining aspect ratio. |
| 156 void ComputeScaleMaxPixels(int frame_width, int frame_height, int max_pixels, | 156 void ComputeScaleMaxPixels(int frame_width, int frame_height, int max_pixels, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 178 int* scaled_width, int* scaled_height); | 178 int* scaled_width, int* scaled_height); |
| 179 | 179 |
| 180 ////////////////////////////////////////////////////////////////////////////// | 180 ////////////////////////////////////////////////////////////////////////////// |
| 181 // Definition of VideoFormat. | 181 // Definition of VideoFormat. |
| 182 ////////////////////////////////////////////////////////////////////////////// | 182 ////////////////////////////////////////////////////////////////////////////// |
| 183 | 183 |
| 184 // VideoFormat with Plain Old Data for global variables. | 184 // VideoFormat with Plain Old Data for global variables. |
| 185 struct VideoFormatPod { | 185 struct VideoFormatPod { |
| 186 int width; // Number of pixels. | 186 int width; // Number of pixels. |
| 187 int height; // Number of pixels. | 187 int height; // Number of pixels. |
| 188 int64 interval; // Nanoseconds. | 188 int64_t interval; // Nanoseconds. |
| 189 uint32 fourcc; // Color space. FOURCC_ANY means that any color space is OK. | 189 uint32_t fourcc; // Color space. FOURCC_ANY means that any color space is OK. |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 struct VideoFormat : VideoFormatPod { | 192 struct VideoFormat : VideoFormatPod { |
| 193 static const int64 kMinimumInterval = | 193 static const int64_t kMinimumInterval = |
| 194 rtc::kNumNanosecsPerSec / 10000; // 10k fps. | 194 rtc::kNumNanosecsPerSec / 10000; // 10k fps. |
| 195 | 195 |
| 196 VideoFormat() { | 196 VideoFormat() { |
| 197 Construct(0, 0, 0, 0); | 197 Construct(0, 0, 0, 0); |
| 198 } | 198 } |
| 199 | 199 |
| 200 VideoFormat(int w, int h, int64 interval_ns, uint32 cc) { | 200 VideoFormat(int w, int h, int64_t interval_ns, uint32_t cc) { |
| 201 Construct(w, h, interval_ns, cc); | 201 Construct(w, h, interval_ns, cc); |
| 202 } | 202 } |
| 203 | 203 |
| 204 explicit VideoFormat(const VideoFormatPod& format) { | 204 explicit VideoFormat(const VideoFormatPod& format) { |
| 205 Construct(format.width, format.height, format.interval, format.fourcc); | 205 Construct(format.width, format.height, format.interval, format.fourcc); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void Construct(int w, int h, int64 interval_ns, uint32 cc) { | 208 void Construct(int w, int h, int64_t interval_ns, uint32_t cc) { |
| 209 width = w; | 209 width = w; |
| 210 height = h; | 210 height = h; |
| 211 interval = interval_ns; | 211 interval = interval_ns; |
| 212 fourcc = cc; | 212 fourcc = cc; |
| 213 } | 213 } |
| 214 | 214 |
| 215 static int64 FpsToInterval(int fps) { | 215 static int64_t FpsToInterval(int fps) { |
| 216 return fps ? rtc::kNumNanosecsPerSec / fps : kMinimumInterval; | 216 return fps ? rtc::kNumNanosecsPerSec / fps : kMinimumInterval; |
| 217 } | 217 } |
| 218 | 218 |
| 219 static int IntervalToFps(int64 interval) { | 219 static int IntervalToFps(int64_t interval) { |
| 220 if (!interval) { | 220 if (!interval) { |
| 221 return 0; | 221 return 0; |
| 222 } | 222 } |
| 223 return static_cast<int>(rtc::kNumNanosecsPerSec / interval); | 223 return static_cast<int>(rtc::kNumNanosecsPerSec / interval); |
| 224 } | 224 } |
| 225 | 225 |
| 226 static float IntervalToFpsFloat(int64 interval) { | 226 static float IntervalToFpsFloat(int64_t interval) { |
| 227 if (!interval) { | 227 if (!interval) { |
| 228 return 0.f; | 228 return 0.f; |
| 229 } | 229 } |
| 230 return static_cast<float>(rtc::kNumNanosecsPerSec) / | 230 return static_cast<float>(rtc::kNumNanosecsPerSec) / |
| 231 static_cast<float>(interval); | 231 static_cast<float>(interval); |
| 232 } | 232 } |
| 233 | 233 |
| 234 bool operator==(const VideoFormat& format) const { | 234 bool operator==(const VideoFormat& format) const { |
| 235 return width == format.width && height == format.height && | 235 return width == format.width && height == format.height && |
| 236 interval == format.interval && fourcc == format.fourcc; | 236 interval == format.interval && fourcc == format.fourcc; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 261 format.width * format.height * format.framerate(); | 261 format.width * format.height * format.framerate(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 // Get a string presentation in the form of "fourcc width x height x fps" | 264 // Get a string presentation in the form of "fourcc width x height x fps" |
| 265 std::string ToString() const; | 265 std::string ToString() const; |
| 266 }; | 266 }; |
| 267 | 267 |
| 268 } // namespace cricket | 268 } // namespace cricket |
| 269 | 269 |
| 270 #endif // TALK_MEDIA_BASE_VIDEOCOMMON_H_ // NOLINT | 270 #endif // TALK_MEDIA_BASE_VIDEOCOMMON_H_ // NOLINT |
| OLD | NEW |