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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
74 buffer.WriteUInt32(frame.fourcc); | 74 buffer.WriteUInt32(frame.fourcc); |
75 buffer.WriteUInt32(frame.pixel_width); | 75 buffer.WriteUInt32(frame.pixel_width); |
76 buffer.WriteUInt32(frame.pixel_height); | 76 buffer.WriteUInt32(frame.pixel_height); |
77 buffer.WriteUInt64(frame.elapsed_time); | 77 // Elapsed time is deprecated. |
| 78 const uint64_t dummy_elapsed_time = 0; |
| 79 buffer.WriteUInt64(dummy_elapsed_time); |
78 buffer.WriteUInt64(frame.time_stamp); | 80 buffer.WriteUInt64(frame.time_stamp); |
79 buffer.WriteUInt32(size); | 81 buffer.WriteUInt32(size); |
80 | 82 |
81 // Write the bytebuffer to file. | 83 // Write the bytebuffer to file. |
82 if (rtc::SR_SUCCESS != video_file_.Write(buffer.Data(), | 84 if (rtc::SR_SUCCESS != video_file_.Write(buffer.Data(), |
83 buffer.Length(), | 85 buffer.Length(), |
84 NULL, | 86 NULL, |
85 NULL)) { | 87 NULL)) { |
86 LOG(LS_ERROR) << "Failed to write frame header"; | 88 LOG(LS_ERROR) << "Failed to write frame header"; |
87 return false; | 89 return false; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 ///////////////////////////////////////////////////////////////////// | 158 ///////////////////////////////////////////////////////////////////// |
157 // Implementation of class FileVideoCapturer | 159 // Implementation of class FileVideoCapturer |
158 ///////////////////////////////////////////////////////////////////// | 160 ///////////////////////////////////////////////////////////////////// |
159 static const int64 kNumNanoSecsPerMilliSec = 1000000; | 161 static const int64 kNumNanoSecsPerMilliSec = 1000000; |
160 const char* FileVideoCapturer::kVideoFileDevicePrefix = "video-file:"; | 162 const char* FileVideoCapturer::kVideoFileDevicePrefix = "video-file:"; |
161 | 163 |
162 FileVideoCapturer::FileVideoCapturer() | 164 FileVideoCapturer::FileVideoCapturer() |
163 : frame_buffer_size_(0), | 165 : frame_buffer_size_(0), |
164 file_read_thread_(NULL), | 166 file_read_thread_(NULL), |
165 repeat_(0), | 167 repeat_(0), |
166 start_time_ns_(0), | |
167 last_frame_timestamp_ns_(0), | 168 last_frame_timestamp_ns_(0), |
168 ignore_framerate_(false) { | 169 ignore_framerate_(false) { |
169 } | 170 } |
170 | 171 |
171 FileVideoCapturer::~FileVideoCapturer() { | 172 FileVideoCapturer::~FileVideoCapturer() { |
172 Stop(); | 173 Stop(); |
173 delete[] static_cast<char*>(captured_frame_.data); | 174 delete[] static_cast<char*>(captured_frame_.data); |
174 } | 175 } |
175 | 176 |
176 bool FileVideoCapturer::Init(const Device& device) { | 177 bool FileVideoCapturer::Init(const Device& device) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 LOG(LS_ERROR) << "File not opened yet"; | 237 LOG(LS_ERROR) << "File not opened yet"; |
237 return CS_NO_DEVICE; | 238 return CS_NO_DEVICE; |
238 } else if (!video_file_.SetPosition(0)) { | 239 } else if (!video_file_.SetPosition(0)) { |
239 LOG(LS_ERROR) << "Failed to seek back to beginning of the file"; | 240 LOG(LS_ERROR) << "Failed to seek back to beginning of the file"; |
240 return CS_FAILED; | 241 return CS_FAILED; |
241 } | 242 } |
242 | 243 |
243 SetCaptureFormat(&capture_format); | 244 SetCaptureFormat(&capture_format); |
244 // Create a thread to read the file. | 245 // Create a thread to read the file. |
245 file_read_thread_ = new FileReadThread(this); | 246 file_read_thread_ = new FileReadThread(this); |
246 start_time_ns_ = kNumNanoSecsPerMilliSec * | |
247 static_cast<int64>(rtc::Time()); | |
248 bool ret = file_read_thread_->Start(); | 247 bool ret = file_read_thread_->Start(); |
249 if (ret) { | 248 if (ret) { |
250 LOG(LS_INFO) << "File video capturer '" << GetId() << "' started"; | 249 LOG(LS_INFO) << "File video capturer '" << GetId() << "' started"; |
251 return CS_RUNNING; | 250 return CS_RUNNING; |
252 } else { | 251 } else { |
253 LOG(LS_ERROR) << "File video capturer '" << GetId() << "' failed to start"; | 252 LOG(LS_ERROR) << "File video capturer '" << GetId() << "' failed to start"; |
254 return CS_FAILED; | 253 return CS_FAILED; |
255 } | 254 } |
256 } | 255 } |
257 | 256 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 if (rtc::SR_SUCCESS == sr) { | 294 if (rtc::SR_SUCCESS == sr) { |
296 if (CapturedFrame::kFrameHeaderSize != bytes_read) { | 295 if (CapturedFrame::kFrameHeaderSize != bytes_read) { |
297 return rtc::SR_EOS; | 296 return rtc::SR_EOS; |
298 } | 297 } |
299 rtc::ByteBuffer buffer(header, CapturedFrame::kFrameHeaderSize); | 298 rtc::ByteBuffer buffer(header, CapturedFrame::kFrameHeaderSize); |
300 buffer.ReadUInt32(reinterpret_cast<uint32*>(&frame->width)); | 299 buffer.ReadUInt32(reinterpret_cast<uint32*>(&frame->width)); |
301 buffer.ReadUInt32(reinterpret_cast<uint32*>(&frame->height)); | 300 buffer.ReadUInt32(reinterpret_cast<uint32*>(&frame->height)); |
302 buffer.ReadUInt32(&frame->fourcc); | 301 buffer.ReadUInt32(&frame->fourcc); |
303 buffer.ReadUInt32(&frame->pixel_width); | 302 buffer.ReadUInt32(&frame->pixel_width); |
304 buffer.ReadUInt32(&frame->pixel_height); | 303 buffer.ReadUInt32(&frame->pixel_height); |
305 buffer.ReadUInt64(reinterpret_cast<uint64*>(&frame->elapsed_time)); | 304 // Elapsed time is deprecated. |
| 305 uint64 dummy_elapsed_time; |
| 306 buffer.ReadUInt64(&dummy_elapsed_time); |
306 buffer.ReadUInt64(reinterpret_cast<uint64*>(&frame->time_stamp)); | 307 buffer.ReadUInt64(reinterpret_cast<uint64*>(&frame->time_stamp)); |
307 buffer.ReadUInt32(&frame->data_size); | 308 buffer.ReadUInt32(&frame->data_size); |
308 } | 309 } |
309 | 310 |
310 return sr; | 311 return sr; |
311 } | 312 } |
312 | 313 |
313 // Executed in the context of FileReadThread. | 314 // Executed in the context of FileReadThread. |
314 bool FileVideoCapturer::ReadFrame(bool first_frame, int* wait_time_ms) { | 315 bool FileVideoCapturer::ReadFrame(bool first_frame, int* wait_time_ms) { |
315 uint32 start_read_time_ms = rtc::Time(); | 316 uint32 start_read_time_ms = rtc::Time(); |
316 | 317 |
317 // 1. Signal the previously read frame to downstream. | 318 // 1. Signal the previously read frame to downstream. |
318 if (!first_frame) { | 319 if (!first_frame) { |
319 captured_frame_.time_stamp = kNumNanoSecsPerMilliSec * | 320 captured_frame_.time_stamp = kNumNanoSecsPerMilliSec * |
320 static_cast<int64>(start_read_time_ms); | 321 static_cast<int64>(start_read_time_ms); |
321 captured_frame_.elapsed_time = captured_frame_.time_stamp - start_time_ns_; | |
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |