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

Side by Side Diff: media/base/video_frame.cc

Issue 604743005: VideoCapture: Remove deep frame copy in the border to libJingle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: perkj@s comments 2 Created 6 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
« media/base/video_frame.h ('K') | « media/base/video_frame.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/video_frame.h" 5 #include "media/base/video_frame.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/aligned_memory.h" 12 #include "base/memory/aligned_memory.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "gpu/command_buffer/common/mailbox_holder.h" 14 #include "gpu/command_buffer/common/mailbox_holder.h"
15 #include "media/base/limits.h" 15 #include "media/base/limits.h"
16 #include "media/base/video_util.h" 16 #include "media/base/video_util.h"
17 17
18 #if !defined(MEDIA_FOR_CAST_IOS) 18 #if !defined(MEDIA_FOR_CAST_IOS)
19 #include "third_party/skia/include/core/SkBitmap.h" 19 #include "third_party/skia/include/core/SkBitmap.h"
20 #endif 20 #endif
21 21
22 namespace media { 22 namespace media {
23 23
24 static inline size_t RoundUp(size_t value, size_t alignment) { 24 static inline size_t RoundUp(size_t value, size_t alignment) {
25 // Check that |alignment| is a power of 2. 25 // Check that |alignment| is a power of 2.
26 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); 26 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1)));
27 return ((value + (alignment - 1)) & ~(alignment - 1)); 27 return ((value + (alignment - 1)) & ~(alignment - 1));
28 } 28 }
29 29
30 static inline size_t RoundDown(size_t value, size_t alignment) {
31 // Check that |alignment| is a power of 2.
32 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1)));
33 return value & ~(alignment - 1);
34 }
35
30 // Rounds up |coded_size| if necessary for |format|. 36 // Rounds up |coded_size| if necessary for |format|.
31 static gfx::Size AdjustCodedSize(VideoFrame::Format format, 37 static gfx::Size AdjustCodedSize(VideoFrame::Format format,
32 const gfx::Size& coded_size) { 38 const gfx::Size& coded_size) {
33 gfx::Size new_coded_size(coded_size); 39 gfx::Size new_coded_size(coded_size);
34 switch (format) { 40 switch (format) {
35 case VideoFrame::YV12: 41 case VideoFrame::YV12:
36 case VideoFrame::YV12A: 42 case VideoFrame::YV12A:
37 case VideoFrame::I420: 43 case VideoFrame::I420:
38 case VideoFrame::YV12J: 44 case VideoFrame::YV12J:
39 new_coded_size.set_height(RoundUp(new_coded_size.height(), 2)); 45 new_coded_size.set_height(RoundUp(new_coded_size.height(), 2));
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 } 880 }
875 NOTREACHED() << "Unsupported video frame format/plane: " << format << "/" 881 NOTREACHED() << "Unsupported video frame format/plane: " << format << "/"
876 << plane; 882 << plane;
877 return 0; 883 return 0;
878 } 884 }
879 885
880 int VideoFrame::rows(size_t plane) const { 886 int VideoFrame::rows(size_t plane) const {
881 return Rows(plane, format_, coded_size_.height()); 887 return Rows(plane, format_, coded_size_.height());
882 } 888 }
883 889
884 uint8* VideoFrame::data(size_t plane) const { 890 const uint8* VideoFrame::data(size_t plane) const {
885 DCHECK(IsValidPlane(plane, format_)); 891 DCHECK(IsValidPlane(plane, format_));
886 return data_[plane]; 892 return data_[plane];
887 } 893 }
888 894
895 uint8* VideoFrame::data(size_t plane) {
896 DCHECK(IsValidPlane(plane, format_));
897 return data_[plane];
898 }
899
900 const uint8* VideoFrame::visible_data(size_t plane) const {
901 DCHECK(IsValidPlane(plane, format_));
902 const uint8* coded_data = data(plane);
903 const int coded_stride = stride(plane);
904 const int offset_x = RoundDown(visible_rect_.x(), 2);
scherkus (not reviewing) 2014/10/20 19:30:36 could you add a comment briefly explaining the mat
magjed_chromium 2014/10/22 15:16:39 This is removed now. See comment below.
905 const int offset_y = RoundDown(visible_rect_.y(), 2);
906 switch (plane) {
907 case kYPlane:
908 case kAPlane:
909 return coded_data + offset_y * coded_stride + offset_x;
910 case kUPlane:
911 case kVPlane:
912 return coded_data + offset_y / 2 * coded_stride + offset_x / 2;
scherkus (not reviewing) 2014/10/20 19:30:36 are you sure the division-by-two makes sense even
magjed_chromium 2014/10/22 15:16:39 You are right, it does not make sense. It is hardc
913 default:
scherkus (not reviewing) 2014/10/20 19:30:36 can you list these cases explicitly? if we ever ch
magjed_chromium 2014/10/22 15:16:39 Done. Not applicable anymore.
914 NOTIMPLEMENTED();
915 return NULL;
916 }
917 }
918
919 uint8* VideoFrame::visible_data(size_t plane) {
920 return const_cast<uint8*>(
921 static_cast<const VideoFrame*>(this)->visible_data(plane));
922 }
923
889 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { 924 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const {
890 DCHECK_EQ(format_, NATIVE_TEXTURE); 925 DCHECK_EQ(format_, NATIVE_TEXTURE);
891 return mailbox_holder_.get(); 926 return mailbox_holder_.get();
892 } 927 }
893 928
894 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { 929 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const {
895 return shared_memory_handle_; 930 return shared_memory_handle_;
896 } 931 }
897 932
898 void VideoFrame::UpdateReleaseSyncPoint(SyncPointClient* client) { 933 void VideoFrame::UpdateReleaseSyncPoint(SyncPointClient* client) {
(...skipping 25 matching lines...) Expand all
924 break; 959 break;
925 for (int row = 0; row < rows(plane); ++row) { 960 for (int row = 0; row < rows(plane); ++row) {
926 base::MD5Update(context, base::StringPiece( 961 base::MD5Update(context, base::StringPiece(
927 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 962 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
928 row_bytes(plane))); 963 row_bytes(plane)));
929 } 964 }
930 } 965 }
931 } 966 }
932 967
933 } // namespace media 968 } // namespace media
OLDNEW
« media/base/video_frame.h ('K') | « media/base/video_frame.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698