OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004--2014 Google Inc. | 3 * Copyright 2004--2014 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 133 } |
134 | 134 |
135 CaptureState YuvFramesCapturer::Start(const VideoFormat& capture_format) { | 135 CaptureState YuvFramesCapturer::Start(const VideoFormat& capture_format) { |
136 if (IsRunning()) { | 136 if (IsRunning()) { |
137 LOG(LS_ERROR) << "Yuv Frame Generator is already running"; | 137 LOG(LS_ERROR) << "Yuv Frame Generator is already running"; |
138 return CS_FAILED; | 138 return CS_FAILED; |
139 } | 139 } |
140 SetCaptureFormat(&capture_format); | 140 SetCaptureFormat(&capture_format); |
141 | 141 |
142 barcode_reference_timestamp_millis_ = | 142 barcode_reference_timestamp_millis_ = |
143 static_cast<int64>(rtc::Time()) * 1000; | 143 static_cast<int64_t>(rtc::Time()) * 1000; |
144 // Create a thread to generate frames. | 144 // Create a thread to generate frames. |
145 frames_generator_thread = new YuvFramesThread(this); | 145 frames_generator_thread = new YuvFramesThread(this); |
146 bool ret = frames_generator_thread->Start(); | 146 bool ret = frames_generator_thread->Start(); |
147 if (ret) { | 147 if (ret) { |
148 LOG(LS_INFO) << "Yuv Frame Generator started"; | 148 LOG(LS_INFO) << "Yuv Frame Generator started"; |
149 return CS_RUNNING; | 149 return CS_RUNNING; |
150 } else { | 150 } else { |
151 LOG(LS_ERROR) << "Yuv Frame Generator failed to start"; | 151 LOG(LS_ERROR) << "Yuv Frame Generator failed to start"; |
152 return CS_FAILED; | 152 return CS_FAILED; |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 bool YuvFramesCapturer::IsRunning() { | 156 bool YuvFramesCapturer::IsRunning() { |
157 return frames_generator_thread && !frames_generator_thread->Finished(); | 157 return frames_generator_thread && !frames_generator_thread->Finished(); |
158 } | 158 } |
159 | 159 |
160 void YuvFramesCapturer::Stop() { | 160 void YuvFramesCapturer::Stop() { |
161 if (frames_generator_thread) { | 161 if (frames_generator_thread) { |
162 frames_generator_thread->Stop(); | 162 frames_generator_thread->Stop(); |
163 frames_generator_thread = NULL; | 163 frames_generator_thread = NULL; |
164 LOG(LS_INFO) << "Yuv Frame Generator stopped"; | 164 LOG(LS_INFO) << "Yuv Frame Generator stopped"; |
165 } | 165 } |
166 SetCaptureFormat(NULL); | 166 SetCaptureFormat(NULL); |
167 } | 167 } |
168 | 168 |
169 bool YuvFramesCapturer::GetPreferredFourccs(std::vector<uint32>* fourccs) { | 169 bool YuvFramesCapturer::GetPreferredFourccs(std::vector<uint32_t>* fourccs) { |
170 if (!fourccs) { | 170 if (!fourccs) { |
171 return false; | 171 return false; |
172 } | 172 } |
173 fourccs->push_back(GetSupportedFormats()->at(0).fourcc); | 173 fourccs->push_back(GetSupportedFormats()->at(0).fourcc); |
174 return true; | 174 return true; |
175 } | 175 } |
176 | 176 |
177 // Executed in the context of YuvFramesThread. | 177 // Executed in the context of YuvFramesThread. |
178 void YuvFramesCapturer::ReadFrame(bool first_frame) { | 178 void YuvFramesCapturer::ReadFrame(bool first_frame) { |
179 // 1. Signal the previously read frame to downstream. | 179 // 1. Signal the previously read frame to downstream. |
180 if (!first_frame) { | 180 if (!first_frame) { |
181 SignalFrameCaptured(this, &captured_frame_); | 181 SignalFrameCaptured(this, &captured_frame_); |
182 } | 182 } |
183 uint8* buffer = new uint8[frame_data_size_]; | 183 uint8_t* buffer = new uint8_t[frame_data_size_]; |
184 frame_generator_->GenerateNextFrame(buffer, GetBarcodeValue()); | 184 frame_generator_->GenerateNextFrame(buffer, GetBarcodeValue()); |
185 frame_index_++; | 185 frame_index_++; |
186 memmove(captured_frame_.data, buffer, frame_data_size_); | 186 memmove(captured_frame_.data, buffer, frame_data_size_); |
187 delete[] buffer; | 187 delete[] buffer; |
188 } | 188 } |
189 | 189 |
190 | 190 int32_t YuvFramesCapturer::GetBarcodeValue() { |
191 int32 YuvFramesCapturer::GetBarcodeValue() { | |
192 if (barcode_reference_timestamp_millis_ == -1 || | 191 if (barcode_reference_timestamp_millis_ == -1 || |
193 frame_index_ % barcode_interval_ != 0) { | 192 frame_index_ % barcode_interval_ != 0) { |
194 return -1; | 193 return -1; |
195 } | 194 } |
196 int64 now_millis = static_cast<int64>(rtc::Time()) * 1000; | 195 int64_t now_millis = static_cast<int64_t>(rtc::Time()) * 1000; |
197 return static_cast<int32>(now_millis - barcode_reference_timestamp_millis_); | 196 return static_cast<int32_t>(now_millis - barcode_reference_timestamp_millis_); |
198 } | 197 } |
199 | 198 |
200 } // namespace cricket | 199 } // namespace cricket |
OLD | NEW |