Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: talk/media/devices/filevideocapturer.cc

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/media/devices/filevideocapturer.h ('k') | talk/media/devices/gdivideorenderer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 void VideoRecorder::Stop() { 53 void VideoRecorder::Stop() {
54 video_file_.Close(); 54 video_file_.Close();
55 } 55 }
56 56
57 bool VideoRecorder::RecordFrame(const CapturedFrame& frame) { 57 bool VideoRecorder::RecordFrame(const CapturedFrame& frame) {
58 if (rtc::SS_CLOSED == video_file_.GetState()) { 58 if (rtc::SS_CLOSED == video_file_.GetState()) {
59 LOG(LS_ERROR) << "File not opened yet"; 59 LOG(LS_ERROR) << "File not opened yet";
60 return false; 60 return false;
61 } 61 }
62 62
63 uint32 size = 0; 63 uint32_t size = 0;
64 if (!frame.GetDataSize(&size)) { 64 if (!frame.GetDataSize(&size)) {
65 LOG(LS_ERROR) << "Unable to calculate the data size of the frame"; 65 LOG(LS_ERROR) << "Unable to calculate the data size of the frame";
66 return false; 66 return false;
67 } 67 }
68 68
69 if (write_header_) { 69 if (write_header_) {
70 // Convert the frame header to bytebuffer. 70 // Convert the frame header to bytebuffer.
71 rtc::ByteBuffer buffer; 71 rtc::ByteBuffer buffer;
72 buffer.WriteUInt32(frame.width); 72 buffer.WriteUInt32(frame.width);
73 buffer.WriteUInt32(frame.height); 73 buffer.WriteUInt32(frame.height);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 FileVideoCapturer* capturer_; 151 FileVideoCapturer* capturer_;
152 mutable rtc::CriticalSection crit_; 152 mutable rtc::CriticalSection crit_;
153 bool finished_; 153 bool finished_;
154 154
155 RTC_DISALLOW_COPY_AND_ASSIGN(FileReadThread); 155 RTC_DISALLOW_COPY_AND_ASSIGN(FileReadThread);
156 }; 156 };
157 157
158 ///////////////////////////////////////////////////////////////////// 158 /////////////////////////////////////////////////////////////////////
159 // Implementation of class FileVideoCapturer 159 // Implementation of class FileVideoCapturer
160 ///////////////////////////////////////////////////////////////////// 160 /////////////////////////////////////////////////////////////////////
161 static const int64 kNumNanoSecsPerMilliSec = 1000000; 161 static const int64_t kNumNanoSecsPerMilliSec = 1000000;
162 const char* FileVideoCapturer::kVideoFileDevicePrefix = "video-file:"; 162 const char* FileVideoCapturer::kVideoFileDevicePrefix = "video-file:";
163 163
164 FileVideoCapturer::FileVideoCapturer() 164 FileVideoCapturer::FileVideoCapturer()
165 : frame_buffer_size_(0), 165 : frame_buffer_size_(0),
166 file_read_thread_(NULL), 166 file_read_thread_(NULL),
167 repeat_(0), 167 repeat_(0),
168 last_frame_timestamp_ns_(0), 168 last_frame_timestamp_ns_(0),
169 ignore_framerate_(false) { 169 ignore_framerate_(false) {
170 } 170 }
171 171
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 260
261 void FileVideoCapturer::Stop() { 261 void FileVideoCapturer::Stop() {
262 if (file_read_thread_) { 262 if (file_read_thread_) {
263 file_read_thread_->Stop(); 263 file_read_thread_->Stop();
264 file_read_thread_ = NULL; 264 file_read_thread_ = NULL;
265 LOG(LS_INFO) << "File video capturer '" << GetId() << "' stopped"; 265 LOG(LS_INFO) << "File video capturer '" << GetId() << "' stopped";
266 } 266 }
267 SetCaptureFormat(NULL); 267 SetCaptureFormat(NULL);
268 } 268 }
269 269
270 bool FileVideoCapturer::GetPreferredFourccs(std::vector<uint32>* fourccs) { 270 bool FileVideoCapturer::GetPreferredFourccs(std::vector<uint32_t>* fourccs) {
271 if (!fourccs) { 271 if (!fourccs) {
272 return false; 272 return false;
273 } 273 }
274 274
275 fourccs->push_back(GetSupportedFormats()->at(0).fourcc); 275 fourccs->push_back(GetSupportedFormats()->at(0).fourcc);
276 return true; 276 return true;
277 } 277 }
278 278
279 rtc::StreamResult FileVideoCapturer::ReadFrameHeader( 279 rtc::StreamResult FileVideoCapturer::ReadFrameHeader(
280 CapturedFrame* frame) { 280 CapturedFrame* frame) {
281 // We first read kFrameHeaderSize bytes from the file stream to a memory 281 // We first read kFrameHeaderSize bytes from the file stream to a memory
282 // buffer, then construct a bytebuffer from the memory buffer, and finally 282 // buffer, then construct a bytebuffer from the memory buffer, and finally
283 // read the frame header from the bytebuffer. 283 // read the frame header from the bytebuffer.
284 char header[CapturedFrame::kFrameHeaderSize]; 284 char header[CapturedFrame::kFrameHeaderSize];
285 rtc::StreamResult sr; 285 rtc::StreamResult sr;
286 size_t bytes_read; 286 size_t bytes_read;
287 int error; 287 int error;
288 sr = video_file_.Read(header, 288 sr = video_file_.Read(header,
289 CapturedFrame::kFrameHeaderSize, 289 CapturedFrame::kFrameHeaderSize,
290 &bytes_read, 290 &bytes_read,
291 &error); 291 &error);
292 LOG(LS_VERBOSE) << "Read frame header: stream_result = " << sr 292 LOG(LS_VERBOSE) << "Read frame header: stream_result = " << sr
293 << ", bytes read = " << bytes_read << ", error = " << error; 293 << ", bytes read = " << bytes_read << ", error = " << error;
294 if (rtc::SR_SUCCESS == sr) { 294 if (rtc::SR_SUCCESS == sr) {
295 if (CapturedFrame::kFrameHeaderSize != bytes_read) { 295 if (CapturedFrame::kFrameHeaderSize != bytes_read) {
296 return rtc::SR_EOS; 296 return rtc::SR_EOS;
297 } 297 }
298 rtc::ByteBuffer buffer(header, CapturedFrame::kFrameHeaderSize); 298 rtc::ByteBuffer buffer(header, CapturedFrame::kFrameHeaderSize);
299 buffer.ReadUInt32(reinterpret_cast<uint32*>(&frame->width)); 299 buffer.ReadUInt32(reinterpret_cast<uint32_t*>(&frame->width));
300 buffer.ReadUInt32(reinterpret_cast<uint32*>(&frame->height)); 300 buffer.ReadUInt32(reinterpret_cast<uint32_t*>(&frame->height));
301 buffer.ReadUInt32(&frame->fourcc); 301 buffer.ReadUInt32(&frame->fourcc);
302 buffer.ReadUInt32(&frame->pixel_width); 302 buffer.ReadUInt32(&frame->pixel_width);
303 buffer.ReadUInt32(&frame->pixel_height); 303 buffer.ReadUInt32(&frame->pixel_height);
304 // Elapsed time is deprecated. 304 // Elapsed time is deprecated.
305 uint64 dummy_elapsed_time; 305 uint64_t dummy_elapsed_time;
306 buffer.ReadUInt64(&dummy_elapsed_time); 306 buffer.ReadUInt64(&dummy_elapsed_time);
307 buffer.ReadUInt64(reinterpret_cast<uint64*>(&frame->time_stamp)); 307 buffer.ReadUInt64(reinterpret_cast<uint64_t*>(&frame->time_stamp));
308 buffer.ReadUInt32(&frame->data_size); 308 buffer.ReadUInt32(&frame->data_size);
309 } 309 }
310 310
311 return sr; 311 return sr;
312 } 312 }
313 313
314 // Executed in the context of FileReadThread. 314 // Executed in the context of FileReadThread.
315 bool FileVideoCapturer::ReadFrame(bool first_frame, int* wait_time_ms) { 315 bool FileVideoCapturer::ReadFrame(bool first_frame, int* wait_time_ms) {
316 uint32 start_read_time_ms = rtc::Time(); 316 uint32_t start_read_time_ms = rtc::Time();
317 317
318 // 1. Signal the previously read frame to downstream. 318 // 1. Signal the previously read frame to downstream.
319 if (!first_frame) { 319 if (!first_frame) {
320 captured_frame_.time_stamp = kNumNanoSecsPerMilliSec * 320 captured_frame_.time_stamp =
321 static_cast<int64>(start_read_time_ms); 321 kNumNanoSecsPerMilliSec * static_cast<int64_t>(start_read_time_ms);
322 SignalFrameCaptured(this, &captured_frame_); 322 SignalFrameCaptured(this, &captured_frame_);
323 } 323 }
324 324
325 // 2. Read the next frame. 325 // 2. Read the next frame.
326 if (rtc::SS_CLOSED == video_file_.GetState()) { 326 if (rtc::SS_CLOSED == video_file_.GetState()) {
327 LOG(LS_ERROR) << "File not opened yet"; 327 LOG(LS_ERROR) << "File not opened yet";
328 return false; 328 return false;
329 } 329 }
330 // 2.1 Read the frame header. 330 // 2.1 Read the frame header.
331 rtc::StreamResult result = ReadFrameHeader(&captured_frame_); 331 rtc::StreamResult result = ReadFrameHeader(&captured_frame_);
(...skipping 28 matching lines...) Expand all
360 return false; 360 return false;
361 } 361 }
362 362
363 // 3. Decide how long to wait for the next frame. 363 // 3. Decide how long to wait for the next frame.
364 *wait_time_ms = 0; 364 *wait_time_ms = 0;
365 365
366 // If the capture format's interval is not kMinimumInterval, we use it to 366 // If the capture format's interval is not kMinimumInterval, we use it to
367 // control the rate; otherwise, we use the timestamp in the file to control 367 // control the rate; otherwise, we use the timestamp in the file to control
368 // the rate. 368 // the rate.
369 if (!first_frame && !ignore_framerate_) { 369 if (!first_frame && !ignore_framerate_) {
370 int64 interval_ns = 370 int64_t interval_ns =
371 GetCaptureFormat()->interval > VideoFormat::kMinimumInterval ? 371 GetCaptureFormat()->interval > VideoFormat::kMinimumInterval
372 GetCaptureFormat()->interval : 372 ? GetCaptureFormat()->interval
373 captured_frame_.time_stamp - last_frame_timestamp_ns_; 373 : captured_frame_.time_stamp - last_frame_timestamp_ns_;
374 int interval_ms = static_cast<int>(interval_ns / kNumNanoSecsPerMilliSec); 374 int interval_ms = static_cast<int>(interval_ns / kNumNanoSecsPerMilliSec);
375 interval_ms -= rtc::Time() - start_read_time_ms; 375 interval_ms -= rtc::Time() - start_read_time_ms;
376 if (interval_ms > 0) { 376 if (interval_ms > 0) {
377 *wait_time_ms = interval_ms; 377 *wait_time_ms = interval_ms;
378 } 378 }
379 } 379 }
380 // Keep the original timestamp read from the file. 380 // Keep the original timestamp read from the file.
381 last_frame_timestamp_ns_ = captured_frame_.time_stamp; 381 last_frame_timestamp_ns_ = captured_frame_.time_stamp;
382 return true; 382 return true;
383 } 383 }
384 384
385 } // namespace cricket 385 } // namespace cricket
OLDNEW
« no previous file with comments | « talk/media/devices/filevideocapturer.h ('k') | talk/media/devices/gdivideorenderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698