OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 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 25 matching lines...) Expand all Loading... |
36 // A hack for avoiding deep frame copies in | 36 // A hack for avoiding deep frame copies in |
37 // cricket::VideoCapturer.SignalFrameCaptured() using a custom FrameFactory. | 37 // cricket::VideoCapturer.SignalFrameCaptured() using a custom FrameFactory. |
38 // A frame is injected using UpdateCapturedFrame(), and converted into a | 38 // A frame is injected using UpdateCapturedFrame(), and converted into a |
39 // cricket::VideoFrame with CreateAliasedFrame(). UpdateCapturedFrame() should | 39 // cricket::VideoFrame with CreateAliasedFrame(). UpdateCapturedFrame() should |
40 // be called before CreateAliasedFrame() for every frame. | 40 // be called before CreateAliasedFrame() for every frame. |
41 // TODO(magjed): Add an interface cricket::VideoCapturer::OnFrameCaptured() | 41 // TODO(magjed): Add an interface cricket::VideoCapturer::OnFrameCaptured() |
42 // for ref counted I420 frames instead of this hack. | 42 // for ref counted I420 frames instead of this hack. |
43 class AndroidVideoCapturer::FrameFactory : public cricket::VideoFrameFactory { | 43 class AndroidVideoCapturer::FrameFactory : public cricket::VideoFrameFactory { |
44 public: | 44 public: |
45 FrameFactory(const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate) | 45 FrameFactory(const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate) |
46 : start_time_(rtc::TimeNanos()), delegate_(delegate) { | 46 : delegate_(delegate) { |
47 // Create a CapturedFrame that only contains header information, not the | 47 // Create a CapturedFrame that only contains header information, not the |
48 // actual pixel data. | 48 // actual pixel data. |
49 captured_frame_.pixel_height = 1; | 49 captured_frame_.pixel_height = 1; |
50 captured_frame_.pixel_width = 1; | 50 captured_frame_.pixel_width = 1; |
51 captured_frame_.data = nullptr; | 51 captured_frame_.data = nullptr; |
52 captured_frame_.data_size = cricket::CapturedFrame::kUnknownDataSize; | 52 captured_frame_.data_size = cricket::CapturedFrame::kUnknownDataSize; |
53 captured_frame_.fourcc = static_cast<uint32>(cricket::FOURCC_ANY); | 53 captured_frame_.fourcc = static_cast<uint32>(cricket::FOURCC_ANY); |
54 } | 54 } |
55 | 55 |
56 void UpdateCapturedFrame( | 56 void UpdateCapturedFrame( |
57 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, | 57 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, |
58 int rotation, | 58 int rotation, |
59 int64 time_stamp_in_ns) { | 59 int64 time_stamp_in_ns) { |
60 buffer_ = buffer; | 60 buffer_ = buffer; |
61 captured_frame_.width = buffer->width(); | 61 captured_frame_.width = buffer->width(); |
62 captured_frame_.height = buffer->height(); | 62 captured_frame_.height = buffer->height(); |
63 captured_frame_.elapsed_time = rtc::TimeNanos() - start_time_; | |
64 captured_frame_.time_stamp = time_stamp_in_ns; | 63 captured_frame_.time_stamp = time_stamp_in_ns; |
65 captured_frame_.rotation = rotation; | 64 captured_frame_.rotation = rotation; |
66 } | 65 } |
67 | 66 |
68 void ClearCapturedFrame() { | 67 void ClearCapturedFrame() { |
69 buffer_ = nullptr; | 68 buffer_ = nullptr; |
70 captured_frame_.width = 0; | 69 captured_frame_.width = 0; |
71 captured_frame_.height = 0; | 70 captured_frame_.height = 0; |
72 captured_frame_.elapsed_time = 0; | |
73 captured_frame_.time_stamp = 0; | 71 captured_frame_.time_stamp = 0; |
74 } | 72 } |
75 | 73 |
76 const cricket::CapturedFrame* GetCapturedFrame() const { | 74 const cricket::CapturedFrame* GetCapturedFrame() const { |
77 return &captured_frame_; | 75 return &captured_frame_; |
78 } | 76 } |
79 | 77 |
80 cricket::VideoFrame* CreateAliasedFrame( | 78 cricket::VideoFrame* CreateAliasedFrame( |
81 const cricket::CapturedFrame* captured_frame, | 79 const cricket::CapturedFrame* captured_frame, |
82 int dst_width, | 80 int dst_width, |
83 int dst_height) const override { | 81 int dst_height) const override { |
84 // Check that captured_frame is actually our frame. | 82 // Check that captured_frame is actually our frame. |
85 RTC_CHECK(captured_frame == &captured_frame_); | 83 RTC_CHECK(captured_frame == &captured_frame_); |
86 rtc::scoped_ptr<cricket::VideoFrame> frame(new cricket::WebRtcVideoFrame( | 84 rtc::scoped_ptr<cricket::VideoFrame> frame(new cricket::WebRtcVideoFrame( |
87 ShallowCenterCrop(buffer_, dst_width, dst_height), | 85 ShallowCenterCrop(buffer_, dst_width, dst_height), |
88 captured_frame->elapsed_time, captured_frame->time_stamp, | 86 captured_frame->time_stamp, captured_frame->GetRotation())); |
89 captured_frame->GetRotation())); | |
90 // Caller takes ownership. | 87 // Caller takes ownership. |
91 // TODO(magjed): Change CreateAliasedFrame() to return a rtc::scoped_ptr. | 88 // TODO(magjed): Change CreateAliasedFrame() to return a rtc::scoped_ptr. |
92 return apply_rotation_ ? frame->GetCopyWithRotationApplied()->Copy() | 89 return apply_rotation_ ? frame->GetCopyWithRotationApplied()->Copy() |
93 : frame.release(); | 90 : frame.release(); |
94 } | 91 } |
95 | 92 |
96 private: | 93 private: |
97 uint64 start_time_; | |
98 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer_; | 94 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer_; |
99 cricket::CapturedFrame captured_frame_; | 95 cricket::CapturedFrame captured_frame_; |
100 rtc::scoped_refptr<AndroidVideoCapturerDelegate> delegate_; | 96 rtc::scoped_refptr<AndroidVideoCapturerDelegate> delegate_; |
101 }; | 97 }; |
102 | 98 |
103 AndroidVideoCapturer::AndroidVideoCapturer( | 99 AndroidVideoCapturer::AndroidVideoCapturer( |
104 const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate) | 100 const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate) |
105 : running_(false), | 101 : running_(false), |
106 delegate_(delegate), | 102 delegate_(delegate), |
107 frame_factory_(NULL), | 103 frame_factory_(NULL), |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 210 |
215 bool AndroidVideoCapturer::GetBestCaptureFormat( | 211 bool AndroidVideoCapturer::GetBestCaptureFormat( |
216 const cricket::VideoFormat& desired, | 212 const cricket::VideoFormat& desired, |
217 cricket::VideoFormat* best_format) { | 213 cricket::VideoFormat* best_format) { |
218 // Delegate this choice to VideoCapturerAndroid.startCapture(). | 214 // Delegate this choice to VideoCapturerAndroid.startCapture(). |
219 *best_format = desired; | 215 *best_format = desired; |
220 return true; | 216 return true; |
221 } | 217 } |
222 | 218 |
223 } // namespace webrtc | 219 } // namespace webrtc |
OLD | NEW |