| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // Default supported formats. Use ResetSupportedFormats to over write. | 57 // Default supported formats. Use ResetSupportedFormats to over write. |
| 58 std::vector<cricket::VideoFormat> formats; | 58 std::vector<cricket::VideoFormat> formats; |
| 59 formats.push_back(cricket::VideoFormat(1280, 720, | 59 formats.push_back(cricket::VideoFormat(1280, 720, |
| 60 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 60 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 61 formats.push_back(cricket::VideoFormat(640, 480, | 61 formats.push_back(cricket::VideoFormat(640, 480, |
| 62 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 62 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 63 formats.push_back(cricket::VideoFormat(320, 240, | 63 formats.push_back(cricket::VideoFormat(320, 240, |
| 64 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 64 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 65 formats.push_back(cricket::VideoFormat(160, 120, | 65 formats.push_back(cricket::VideoFormat(160, 120, |
| 66 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 66 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 67 formats.push_back(cricket::VideoFormat(1280, 720, |
| 68 cricket::VideoFormat::FpsToInterval(60), cricket::FOURCC_I420)); |
| 67 ResetSupportedFormats(formats); | 69 ResetSupportedFormats(formats); |
| 68 } | 70 } |
| 69 ~FakeVideoCapturer() { | 71 ~FakeVideoCapturer() { |
| 70 SignalDestroyed(this); | 72 SignalDestroyed(this); |
| 71 } | 73 } |
| 72 | 74 |
| 73 void ResetSupportedFormats(const std::vector<cricket::VideoFormat>& formats) { | 75 void ResetSupportedFormats(const std::vector<cricket::VideoFormat>& formats) { |
| 74 SetSupportedFormats(formats); | 76 SetSupportedFormats(formats); |
| 75 } | 77 } |
| 76 bool CaptureFrame() { | 78 bool CaptureFrame() { |
| 77 if (!GetCaptureFormat()) { | 79 if (!GetCaptureFormat()) { |
| 78 return false; | 80 return false; |
| 79 } | 81 } |
| 80 return CaptureCustomFrame(GetCaptureFormat()->width, | 82 return CaptureCustomFrame(GetCaptureFormat()->width, |
| 81 GetCaptureFormat()->height, | 83 GetCaptureFormat()->height, |
| 84 GetCaptureFormat()->interval, |
| 82 GetCaptureFormat()->fourcc); | 85 GetCaptureFormat()->fourcc); |
| 83 } | 86 } |
| 84 bool CaptureCustomFrame(int width, int height, uint32 fourcc) { | 87 bool CaptureCustomFrame(int width, int height, uint32 fourcc) { |
| 88 // default to 30fps |
| 89 return CaptureCustomFrame(width, height, 33333333, fourcc); |
| 90 } |
| 91 bool CaptureCustomFrame(int width, |
| 92 int height, |
| 93 int64_t timestamp_interval, |
| 94 uint32 fourcc) { |
| 85 if (!running_) { | 95 if (!running_) { |
| 86 return false; | 96 return false; |
| 87 } | 97 } |
| 88 // Currently, |fourcc| is always I420 or ARGB. | 98 // Currently, |fourcc| is always I420 or ARGB. |
| 89 // TODO(fbarchard): Extend SizeOf to take fourcc. | 99 // TODO(fbarchard): Extend SizeOf to take fourcc. |
| 90 uint32 size = 0u; | 100 uint32 size = 0u; |
| 91 if (fourcc == cricket::FOURCC_ARGB) { | 101 if (fourcc == cricket::FOURCC_ARGB) { |
| 92 size = width * 4 * height; | 102 size = width * 4 * height; |
| 93 } else if (fourcc == cricket::FOURCC_I420) { | 103 } else if (fourcc == cricket::FOURCC_I420) { |
| 94 size = static_cast<uint32>(cricket::VideoFrame::SizeOf(width, height)); | 104 size = static_cast<uint32>(cricket::VideoFrame::SizeOf(width, height)); |
| 95 } else { | 105 } else { |
| 96 return false; // Unsupported FOURCC. | 106 return false; // Unsupported FOURCC. |
| 97 } | 107 } |
| 98 if (size == 0u) { | 108 if (size == 0u) { |
| 99 return false; // Width and/or Height were zero. | 109 return false; // Width and/or Height were zero. |
| 100 } | 110 } |
| 101 | 111 |
| 102 cricket::CapturedFrame frame; | 112 cricket::CapturedFrame frame; |
| 103 frame.width = width; | 113 frame.width = width; |
| 104 frame.height = height; | 114 frame.height = height; |
| 105 frame.fourcc = fourcc; | 115 frame.fourcc = fourcc; |
| 106 frame.data_size = size; | 116 frame.data_size = size; |
| 107 frame.elapsed_time = next_timestamp_; | 117 frame.elapsed_time = next_timestamp_; |
| 108 frame.time_stamp = initial_unix_timestamp_ + next_timestamp_; | 118 frame.time_stamp = initial_unix_timestamp_ + next_timestamp_; |
| 109 next_timestamp_ += 33333333; // 30 fps | 119 next_timestamp_ += timestamp_interval; |
| 110 | 120 |
| 111 rtc::scoped_ptr<char[]> data(new char[size]); | 121 rtc::scoped_ptr<char[]> data(new char[size]); |
| 112 frame.data = data.get(); | 122 frame.data = data.get(); |
| 113 // Copy something non-zero into the buffer so Validate wont complain that | 123 // Copy something non-zero into the buffer so Validate wont complain that |
| 114 // the frame is all duplicate. | 124 // the frame is all duplicate. |
| 115 memset(frame.data, 1, size / 2); | 125 memset(frame.data, 1, size / 2); |
| 116 memset(reinterpret_cast<uint8*>(frame.data) + (size / 2), 2, | 126 memset(reinterpret_cast<uint8*>(frame.data) + (size / 2), 2, |
| 117 size - (size / 2)); | 127 size - (size / 2)); |
| 118 memcpy(frame.data, reinterpret_cast<const uint8*>(&fourcc), 4); | 128 memcpy(frame.data, reinterpret_cast<const uint8*>(&fourcc), 4); |
| 119 frame.rotation = rotation_; | 129 frame.rotation = rotation_; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 bool running_; | 170 bool running_; |
| 161 int64 initial_unix_timestamp_; | 171 int64 initial_unix_timestamp_; |
| 162 int64 next_timestamp_; | 172 int64 next_timestamp_; |
| 163 bool is_screencast_; | 173 bool is_screencast_; |
| 164 webrtc::VideoRotation rotation_; | 174 webrtc::VideoRotation rotation_; |
| 165 }; | 175 }; |
| 166 | 176 |
| 167 } // namespace cricket | 177 } // namespace cricket |
| 168 | 178 |
| 169 #endif // TALK_MEDIA_BASE_FAKEVIDEOCAPTURER_H_ | 179 #endif // TALK_MEDIA_BASE_FAKEVIDEOCAPTURER_H_ |
| OLD | NEW |