Commit cbacab9d authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Media Thumbnail Parser: Use empty implementation when ffmpeg is disabled.

VideoFrameExtractor should not be built when media_use_ffmpeg build
flag is false.

This CL splits ThumbnailMediaParser to an interface and use empty
implementation based on media_use_ffmpeg.

There are other build errors, this CL only fixes the one in
VideoFrameExtractor use case.

Bug: 1066404
Change-Id: Ib856899b4d465a817634b468866d3fb62d7c5053
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2131036Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757195}
parent f5417f2d
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//media/media_options.gni")
if (is_android) { if (is_android) {
import("//build/config/android/config.gni") import("//build/config/android/config.gni")
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
...@@ -42,6 +44,18 @@ source_set("generator") { ...@@ -42,6 +44,18 @@ source_set("generator") {
"android/thumbnail_media_parser.h", "android/thumbnail_media_parser.h",
] ]
if (media_use_ffmpeg) {
sources += [
"android/thumbnail_media_parser_impl.cc",
"android/thumbnail_media_parser_impl.h",
]
} else {
sources += [
"android/noop_thumbnail_media_parser.cc",
"android/noop_thumbnail_media_parser.h",
]
}
deps += [ deps += [
":jni_headers", ":jni_headers",
"//third_party/android_opengl/etc1", "//third_party/android_opengl/etc1",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/thumbnail/generator/android/noop_thumbnail_media_parser.h"
#include "third_party/skia/include/core/SkBitmap.h"
void NoopThumbnailMediaParser::Start(ParseCompleteCB parse_complete_cb) {
DCHECK(parse_complete_cb);
std::move(parse_complete_cb)
.Run(false /*success*/, chrome::mojom::MediaMetadata::New(), SkBitmap());
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_THUMBNAIL_GENERATOR_ANDROID_NOOP_THUMBNAIL_MEDIA_PARSER_H_
#define CHROME_BROWSER_THUMBNAIL_GENERATOR_ANDROID_NOOP_THUMBNAIL_MEDIA_PARSER_H_
#include "chrome/browser/thumbnail/generator/android/thumbnail_media_parser.h"
// Empty implementation used when ENABLE_FFMPEG build flag is false.
class NoopThumbnailMediaParser : public ThumbnailMediaParser {
public:
NoopThumbnailMediaParser() = default;
NoopThumbnailMediaParser(const NoopThumbnailMediaParser&) = delete;
NoopThumbnailMediaParser& operator=(const NoopThumbnailMediaParser&) = delete;
~NoopThumbnailMediaParser() override = default;
private:
// ThumbnailMediaParser implementation.
void Start(ParseCompleteCB parse_complete_cb) override;
};
#endif // CHROME_BROWSER_THUMBNAIL_GENERATOR_ANDROID_NOOP_THUMBNAIL_MEDIA_PARSER_H_
...@@ -106,7 +106,7 @@ void ThumbnailGenerator::RetrieveThumbnail( ...@@ -106,7 +106,7 @@ void ThumbnailGenerator::RetrieveThumbnail(
// Retrieve video thumbnail. // Retrieve video thumbnail.
if (base::StartsWith(mime_type, "video/", if (base::StartsWith(mime_type, "video/",
base::CompareCase::INSENSITIVE_ASCII)) { base::CompareCase::INSENSITIVE_ASCII)) {
auto parser = std::make_unique<ThumbnailMediaParser>(mime_type, file_path); auto parser = ThumbnailMediaParser::Create(mime_type, file_path);
parser->Start(base::BindOnce(&ThumbnailGenerator::OnVideoThumbnailRetrieved, parser->Start(base::BindOnce(&ThumbnailGenerator::OnVideoThumbnailRetrieved,
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr(),
std::move(java_callback), icon_size, std::move(java_callback), icon_size,
......
// Copyright 2019 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -7,132 +7,39 @@ ...@@ -7,132 +7,39 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector>
#include "base/callback.h" #include "base/callback.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/sequenced_task_runner.h"
#include "base/timer/timer.h"
#include "chrome/browser/thumbnail/generator/android/stats.h"
#include "chrome/common/media_galleries/metadata_types.h"
#include "chrome/services/media_gallery_util/public/cpp/media_parser_provider.h" #include "chrome/services/media_gallery_util/public/cpp/media_parser_provider.h"
#include "chrome/services/media_gallery_util/public/mojom/media_parser.mojom-forward.h" #include "chrome/services/media_gallery_util/public/mojom/media_parser.mojom-forward.h"
#include "media/base/media_log.h"
#include "media/mojo/mojom/interface_factory.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace media {
class GpuVideoAcceleratorFactories;
class MediaInterfaceProvider;
class MojoVideoDecoder;
class VideoDecoderConfig;
class VideoThumbnailDecoder;
} // namespace media
class SkBitmap; class SkBitmap;
// Parse local media files, including media metadata and thumbnails. // Parse local media files, including media metadata and thumbnails.
// Metadata is always parsed in utility process for both audio and video files. // Metadata is always parsed in utility process for both audio and video files.
// class ThumbnailMediaParser {
// For video file, the thumbnail will be the a video key frame. The frame
// extraction always happens in utility process. The decoding may happen in
// utility or GPU process based on video codec.
class ThumbnailMediaParser : public MediaParserProvider,
public media::MediaLog {
public: public:
using ParseCompleteCB = using ParseCompleteCB =
base::OnceCallback<void(bool success, base::OnceCallback<void(bool success,
chrome::mojom::MediaMetadataPtr media_metadata, chrome::mojom::MediaMetadataPtr media_metadata,
SkBitmap bitmap)>; SkBitmap bitmap)>;
ThumbnailMediaParser(const std::string& mime_type, // Creates the parser, may return an empty implementation when ffmpeg is
const base::FilePath& file_path); // disabled.
~ThumbnailMediaParser() override; static std::unique_ptr<ThumbnailMediaParser> Create(
const std::string& mime_type,
const base::FilePath& file_path);
ThumbnailMediaParser() = default;
ThumbnailMediaParser(const ThumbnailMediaParser&) = delete;
ThumbnailMediaParser& operator=(const ThumbnailMediaParser&) = delete;
virtual ~ThumbnailMediaParser() = default;
// Parse media metadata and thumbnail in a local file. All file IO will run on // Parse media metadata and thumbnail in a local file. All file IO will run on
// |file_task_runner|. The metadata is parsed in an utility process safely. // |file_task_runner|. The metadata is parsed in an utility process safely.
// The thumbnail is retrieved from GPU process or utility process based on // The thumbnail is retrieved from GPU process or utility process based on
// different codec. // different codec.
void Start(ParseCompleteCB parse_complete_cb); virtual void Start(ParseCompleteCB parse_complete_cb) = 0;
private:
void OnReadFileSize(int64_t file_size);
// MediaParserProvider implementation:
void OnMediaParserCreated() override;
void OnConnectionError() override;
// Called after media metadata are parsed.
void OnMediaMetadataParsed(
bool parse_success,
chrome::mojom::MediaMetadataPtr metadata,
const std::vector<metadata::AttachedImage>& attached_images);
// Retrieves an encoded video frame.
void RetrieveEncodedVideoFrame();
void OnVideoFrameRetrieved(
bool success,
chrome::mojom::VideoFrameDataPtr video_frame_data,
const base::Optional<media::VideoDecoderConfig>& config);
// Decodes the video frame.
void OnGpuVideoAcceleratorFactoriesReady(
std::unique_ptr<media::GpuVideoAcceleratorFactories>);
void DecodeVideoFrame();
void OnVideoFrameDecoded(scoped_refptr<media::VideoFrame> decoded_frame);
// Renders the video frame to bitmap.
void RenderVideoFrame(scoped_refptr<media::VideoFrame> video_frame);
media::mojom::InterfaceFactory* GetMediaInterfaceFactory();
void OnDecoderConnectionError();
// Overlays media data source read operation. Gradually read data from media
// file.
void OnMediaDataReady(chrome::mojom::MediaDataSource::ReadCallback callback,
std::unique_ptr<std::string> data);
void NotifyComplete(SkBitmap bitmap);
void OnError(MediaParserEvent event);
int64_t size_;
std::string mime_type_;
base::FilePath file_path_;
ParseCompleteCB parse_complete_cb_;
chrome::mojom::MediaMetadataPtr metadata_;
// Used to read media files chunks to feed to IPC channel.
std::unique_ptr<chrome::mojom::MediaDataSource> media_data_source_;
// The task runner to do blocking disk IO.
scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
// A timer to prevent unresponsive Android decoder during video file parsing,
// and the parser will fail gracefully after timeout.
base::OneShotTimer timer_;
// Cached video frame data, which contains either encoded frame or decoded
// video frame. Encoded frame is extracted with ffmpeg, the data can be large
// for high resolution video.
chrome::mojom::VideoFrameDataPtr video_frame_data_;
// Objects used to decode the video into media::VideoFrame with
// MojoVideoDecoder.
media::VideoDecoderConfig config_;
std::unique_ptr<media::VideoThumbnailDecoder> decoder_;
mojo::Remote<media::mojom::InterfaceFactory> media_interface_factory_;
std::unique_ptr<media::MediaInterfaceProvider> media_interface_provider_;
std::unique_ptr<media::GpuVideoAcceleratorFactories> gpu_factories_;
bool decode_done_;
base::WeakPtrFactory<ThumbnailMediaParser> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ThumbnailMediaParser);
}; };
#endif // CHROME_BROWSER_THUMBNAIL_GENERATOR_ANDROID_THUMBNAIL_MEDIA_PARSER_H_ #endif // CHROME_BROWSER_THUMBNAIL_GENERATOR_ANDROID_THUMBNAIL_MEDIA_PARSER_H_
...@@ -64,7 +64,7 @@ ThumbnailMediaParserBridge::ThumbnailMediaParserBridge( ...@@ -64,7 +64,7 @@ ThumbnailMediaParserBridge::ThumbnailMediaParserBridge(
const std::string& mime_type, const std::string& mime_type,
const base::FilePath& file_path, const base::FilePath& file_path,
ThumbnailMediaParser::ParseCompleteCB parse_complete_cb) ThumbnailMediaParser::ParseCompleteCB parse_complete_cb)
: parser_(std::make_unique<ThumbnailMediaParser>(mime_type, file_path)), : parser_(ThumbnailMediaParser::Create(mime_type, file_path)),
parse_complete_cb_(std::move(parse_complete_cb)) {} parse_complete_cb_(std::move(parse_complete_cb)) {}
ThumbnailMediaParserBridge::~ThumbnailMediaParserBridge() = default; ThumbnailMediaParserBridge::~ThumbnailMediaParserBridge() = default;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_THUMBNAIL_GENERATOR_ANDROID_THUMBNAIL_MEDIA_PARSER_IMPL_H_
#define CHROME_BROWSER_THUMBNAIL_GENERATOR_ANDROID_THUMBNAIL_MEDIA_PARSER_IMPL_H_
#include <memory>
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/sequenced_task_runner.h"
#include "base/timer/timer.h"
#include "chrome/browser/thumbnail/generator/android/stats.h"
#include "chrome/browser/thumbnail/generator/android/thumbnail_media_parser.h"
#include "chrome/common/media_galleries/metadata_types.h"
#include "media/base/media_log.h"
#include "media/mojo/mojom/interface_factory.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace media {
class GpuVideoAcceleratorFactories;
class MediaInterfaceProvider;
class MojoVideoDecoder;
class VideoDecoderConfig;
class VideoThumbnailDecoder;
} // namespace media
class SkBitmap;
// Parse media file in remote process using ffmpeg to extract video frame.
// The decoding may happen in utility or GPU process based on video codec.
// For video file, the thumbnail will be the a video key frame.
class ThumbnailMediaParserImpl : public ThumbnailMediaParser,
public MediaParserProvider,
public media::MediaLog {
public:
ThumbnailMediaParserImpl(const std::string& mime_type,
const base::FilePath& file_path);
~ThumbnailMediaParserImpl() override;
// ThumbnailMediaParser implementation.
void Start(ParseCompleteCB parse_complete_cb) override;
private:
void OnReadFileSize(int64_t file_size);
// MediaParserProvider implementation:
void OnMediaParserCreated() override;
void OnConnectionError() override;
// Called after media metadata are parsed.
void OnMediaMetadataParsed(
bool parse_success,
chrome::mojom::MediaMetadataPtr metadata,
const std::vector<metadata::AttachedImage>& attached_images);
// Retrieves an encoded video frame.
void RetrieveEncodedVideoFrame();
void OnVideoFrameRetrieved(
bool success,
chrome::mojom::VideoFrameDataPtr video_frame_data,
const base::Optional<media::VideoDecoderConfig>& config);
// Decodes the video frame.
void OnGpuVideoAcceleratorFactoriesReady(
std::unique_ptr<media::GpuVideoAcceleratorFactories>);
void DecodeVideoFrame();
void OnVideoFrameDecoded(scoped_refptr<media::VideoFrame> decoded_frame);
// Renders the video frame to bitmap.
void RenderVideoFrame(scoped_refptr<media::VideoFrame> video_frame);
media::mojom::InterfaceFactory* GetMediaInterfaceFactory();
void OnDecoderConnectionError();
// Overlays media data source read operation. Gradually read data from media
// file.
void OnMediaDataReady(chrome::mojom::MediaDataSource::ReadCallback callback,
std::unique_ptr<std::string> data);
void NotifyComplete(SkBitmap bitmap);
void OnError(MediaParserEvent event);
int64_t size_;
std::string mime_type_;
base::FilePath file_path_;
ParseCompleteCB parse_complete_cb_;
chrome::mojom::MediaMetadataPtr metadata_;
// Used to read media files chunks to feed to IPC channel.
std::unique_ptr<chrome::mojom::MediaDataSource> media_data_source_;
// The task runner to do blocking disk IO.
scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
// A timer to prevent unresponsive Android decoder during video file parsing,
// and the parser will fail gracefully after timeout.
base::OneShotTimer timer_;
// Cached video frame data, which contains either encoded frame or decoded
// video frame. Encoded frame is extracted with ffmpeg, the data can be large
// for high resolution video.
chrome::mojom::VideoFrameDataPtr video_frame_data_;
// Objects used to decode the video into media::VideoFrame with
// MojoVideoDecoder.
media::VideoDecoderConfig config_;
std::unique_ptr<media::VideoThumbnailDecoder> decoder_;
mojo::Remote<media::mojom::InterfaceFactory> media_interface_factory_;
std::unique_ptr<media::MediaInterfaceProvider> media_interface_provider_;
std::unique_ptr<media::GpuVideoAcceleratorFactories> gpu_factories_;
bool decode_done_;
base::WeakPtrFactory<ThumbnailMediaParserImpl> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ThumbnailMediaParserImpl);
};
#endif // CHROME_BROWSER_THUMBNAIL_GENERATOR_ANDROID_THUMBNAIL_MEDIA_PARSER_IMPL_H_
...@@ -187,6 +187,13 @@ jumbo_source_set("filters") { ...@@ -187,6 +187,13 @@ jumbo_source_set("filters") {
"ffmpeg_video_decoder.h", "ffmpeg_video_decoder.h",
] ]
} }
if (is_android) {
sources += [
"android/video_frame_extractor.cc",
"android/video_frame_extractor.h",
]
}
} }
if (is_android) { if (is_android) {
...@@ -199,8 +206,6 @@ jumbo_source_set("filters") { ...@@ -199,8 +206,6 @@ jumbo_source_set("filters") {
sources += [ sources += [
"android/media_codec_audio_decoder.cc", "android/media_codec_audio_decoder.cc",
"android/media_codec_audio_decoder.h", "android/media_codec_audio_decoder.h",
"android/video_frame_extractor.cc",
"android/video_frame_extractor.h",
] ]
deps += [ "//media/base/android" ] deps += [ "//media/base/android" ]
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment