| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/renderer/pepper/video_decoder_shim.h" | 5 #include "content/renderer/pepper/video_decoder_shim.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
| 9 #include <GLES2/gl2extchromium.h> | 9 #include <GLES2/gl2extchromium.h> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/numerics/safe_conversions.h" | 16 #include "base/numerics/safe_conversions.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
| 19 #include "cc/blink/context_provider_web_context.h" | 19 #include "cc/blink/context_provider_web_context.h" |
| 20 #include "content/public/renderer/render_thread.h" | 20 #include "content/public/renderer/render_thread.h" |
| 21 #include "content/renderer/pepper/pepper_video_decoder_host.h" | 21 #include "content/renderer/pepper/pepper_video_decoder_host.h" |
| 22 #include "content/renderer/render_thread_impl.h" | 22 #include "content/renderer/render_thread_impl.h" |
| 23 #include "gpu/command_buffer/client/gles2_interface.h" | 23 #include "gpu/command_buffer/client/gles2_interface.h" |
| 24 #include "media/base/cdm_context.h" | 24 #include "media/base/cdm_context.h" |
| 25 #include "media/base/decoder_buffer.h" | 25 #include "media/base/decoder_buffer.h" |
| 26 #include "media/base/limits.h" | 26 #include "media/base/limits.h" |
| 27 #include "media/base/media.h" |
| 27 #include "media/base/media_util.h" | 28 #include "media/base/media_util.h" |
| 28 #include "media/base/video_decoder.h" | 29 #include "media/base/video_decoder.h" |
| 29 #include "media/filters/ffmpeg_video_decoder.h" | 30 #include "media/filters/ffmpeg_video_decoder.h" |
| 30 #include "media/filters/vpx_video_decoder.h" | 31 #include "media/filters/vpx_video_decoder.h" |
| 31 #include "media/renderers/skcanvas_video_renderer.h" | 32 #include "media/renderers/skcanvas_video_renderer.h" |
| 32 #include "media/video/picture.h" | 33 #include "media/video/picture.h" |
| 33 #include "media/video/video_decode_accelerator.h" | 34 #include "media/video/video_decode_accelerator.h" |
| 34 #include "ppapi/c/pp_errors.h" | 35 #include "ppapi/c/pp_errors.h" |
| 35 #include "third_party/skia/include/gpu/GrTypes.h" | 36 #include "third_party/skia/include/gpu/GrTypes.h" |
| 36 | 37 |
| 37 namespace content { | 38 namespace content { |
| 38 | 39 |
| 39 static const uint32_t kGrInvalidateState = | 40 static const uint32_t kGrInvalidateState = |
| 40 kRenderTarget_GrGLBackendState | kTextureBinding_GrGLBackendState | | 41 kRenderTarget_GrGLBackendState | kTextureBinding_GrGLBackendState | |
| 41 kView_GrGLBackendState | kVertex_GrGLBackendState | | 42 kView_GrGLBackendState | kVertex_GrGLBackendState | |
| 42 kProgram_GrGLBackendState | kPixelStore_GrGLBackendState; | 43 kProgram_GrGLBackendState | kPixelStore_GrGLBackendState; |
| 43 | 44 |
| 44 namespace { | |
| 45 | |
| 46 bool IsCodecSupported(media::VideoCodec codec) { | |
| 47 #if !defined(MEDIA_DISABLE_LIBVPX) | |
| 48 if (codec == media::kCodecVP9) | |
| 49 return true; | |
| 50 #endif | |
| 51 | |
| 52 #if !defined(MEDIA_DISABLE_FFMPEG) && !defined(DISABLE_FFMPEG_VIDEO_DECODERS) | |
| 53 return media::FFmpegVideoDecoder::IsCodecSupported(codec); | |
| 54 #else | |
| 55 return false; | |
| 56 #endif | |
| 57 } | |
| 58 | |
| 59 } // namespace | |
| 60 | |
| 61 // YUV->RGB converter class using a shader and FBO. | 45 // YUV->RGB converter class using a shader and FBO. |
| 62 class VideoDecoderShim::YUVConverter { | 46 class VideoDecoderShim::YUVConverter { |
| 63 public: | 47 public: |
| 64 YUVConverter(const scoped_refptr<cc_blink::ContextProviderWebContext>&); | 48 YUVConverter(const scoped_refptr<cc_blink::ContextProviderWebContext>&); |
| 65 ~YUVConverter(); | 49 ~YUVConverter(); |
| 66 bool Initialize(); | 50 bool Initialize(); |
| 67 void Convert(const scoped_refptr<media::VideoFrame>& frame, GLuint tex_out); | 51 void Convert(const scoped_refptr<media::VideoFrame>& frame, GLuint tex_out); |
| 68 | 52 |
| 69 private: | 53 private: |
| 70 GLuint CreateShader(); | 54 GLuint CreateShader(); |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 | 864 |
| 881 media::VideoCodec codec = media::kUnknownVideoCodec; | 865 media::VideoCodec codec = media::kUnknownVideoCodec; |
| 882 if (vda_config.profile <= media::H264PROFILE_MAX) | 866 if (vda_config.profile <= media::H264PROFILE_MAX) |
| 883 codec = media::kCodecH264; | 867 codec = media::kCodecH264; |
| 884 else if (vda_config.profile <= media::VP8PROFILE_MAX) | 868 else if (vda_config.profile <= media::VP8PROFILE_MAX) |
| 885 codec = media::kCodecVP8; | 869 codec = media::kCodecVP8; |
| 886 else if (vda_config.profile <= media::VP9PROFILE_MAX) | 870 else if (vda_config.profile <= media::VP9PROFILE_MAX) |
| 887 codec = media::kCodecVP9; | 871 codec = media::kCodecVP9; |
| 888 DCHECK_NE(codec, media::kUnknownVideoCodec); | 872 DCHECK_NE(codec, media::kUnknownVideoCodec); |
| 889 | 873 |
| 890 if (!IsCodecSupported(codec)) | 874 if (!media::IsVideoCodecSupported(codec)) |
| 891 return false; | 875 return false; |
| 892 | 876 |
| 893 if (!yuv_converter_->Initialize()) | 877 if (!yuv_converter_->Initialize()) |
| 894 return false; | 878 return false; |
| 895 | 879 |
| 896 media::VideoDecoderConfig video_decoder_config( | 880 media::VideoDecoderConfig video_decoder_config( |
| 897 codec, vda_config.profile, media::PIXEL_FORMAT_YV12, | 881 codec, vda_config.profile, media::PIXEL_FORMAT_YV12, |
| 898 media::COLOR_SPACE_UNSPECIFIED, | 882 media::COLOR_SPACE_UNSPECIFIED, |
| 899 gfx::Size(32, 24), // Small sizes that won't fail. | 883 gfx::Size(32, 24), // Small sizes that won't fail. |
| 900 gfx::Rect(32, 24), gfx::Size(32, 24), | 884 gfx::Rect(32, 24), gfx::Size(32, 24), |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 void VideoDecoderShim::DeleteTexture(uint32_t texture_id) { | 1104 void VideoDecoderShim::DeleteTexture(uint32_t texture_id) { |
| 1121 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); | 1105 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); |
| 1122 gles2->DeleteTextures(1, &texture_id); | 1106 gles2->DeleteTextures(1, &texture_id); |
| 1123 } | 1107 } |
| 1124 | 1108 |
| 1125 void VideoDecoderShim::FlushCommandBuffer() { | 1109 void VideoDecoderShim::FlushCommandBuffer() { |
| 1126 context_provider_->ContextGL()->Flush(); | 1110 context_provider_->ContextGL()->Flush(); |
| 1127 } | 1111 } |
| 1128 | 1112 |
| 1129 } // namespace content | 1113 } // namespace content |
| OLD | NEW |