Commit fe2e8506 authored by johnme@chromium.org's avatar johnme@chromium.org

Revert of Clean up. Experimental user avatars removed. (https://codereview.chromium.org/395133002/)

Reason for revert:
This broke build:
http://build.chromium.org/p/chromium.webkit/builders/Linux%20ChromiumOS%20Tests%20%28dbg%29%282%29/builds/419

With error:
/mnt/data/b/build/slave/Linux_ChromiumOS_Tests__dbg__2_/build/src/out/Debug/app_shell_browsertests: symbol lookup error: /mnt/data/b/build/slave/Linux_ChromiumOS_Tests__dbg__2_/build/src/out/Debug/lib/libmedia.so: undefined symbol: Ebml_Serialize

Original issue's description:
> Clean up. Experimental user avatars removed.
> 
> BUG=387738
> 
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=284666

TBR=scherkus@chromium.org,nkostylev@chromium.org,merkulova@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=387738

Review URL: https://codereview.chromium.org/411523005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284676 0039d316-1c4b-4281-b951-d872f2087c98
parent 49d75aea
...@@ -84,6 +84,11 @@ class User : public user_manager::UserInfo { ...@@ -84,6 +84,11 @@ class User : public user_manager::UserInfo {
const user_manager::UserImage::RawImage& raw_image() const { const user_manager::UserImage::RawImage& raw_image() const {
return user_image_.raw_image(); return user_image_.raw_image();
} }
bool has_animated_image() const { return user_image_.has_animated_image(); }
// Returns raw representation of animated user image.
const user_manager::UserImage::RawImage& animated_image() const {
return user_image_.animated_image();
}
// Whether |raw_image| contains data in format that is considered safe to // Whether |raw_image| contains data in format that is considered safe to
// decode in sensitive environment (on Login screen). // decode in sensitive environment (on Login screen).
......
...@@ -9,6 +9,18 @@ cr.define('options', function() { ...@@ -9,6 +9,18 @@ cr.define('options', function() {
/** @const */ var GridSelectionController = cr.ui.GridSelectionController; /** @const */ var GridSelectionController = cr.ui.GridSelectionController;
/** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel;
/**
* Number of frames recorded by takeVideo().
* @const
*/
var RECORD_FRAMES = 48;
/**
* FPS at which camera stream is recorded.
* @const
*/
var RECORD_FPS = 16;
/** /**
* Dimensions for camera capture. * Dimensions for camera capture.
* @const * @const
...@@ -478,6 +490,29 @@ cr.define('options', function() { ...@@ -478,6 +490,29 @@ cr.define('options', function() {
return true; return true;
}, },
/**
* Performs video capture from the live camera stream.
* @param {function=} opt_callback Callback that receives taken video as
* data URL of a vertically stacked PNG sprite.
*/
takeVideo: function(opt_callback) {
var canvas = document.createElement('canvas');
canvas.width = CAPTURE_SIZE.width;
canvas.height = CAPTURE_SIZE.height * RECORD_FRAMES;
var ctx = canvas.getContext('2d');
// Force canvas initialization to prevent FPS lag on the first frame.
ctx.fillRect(0, 0, 1, 1);
var captureData = {
callback: opt_callback,
canvas: canvas,
ctx: ctx,
frameNo: 0,
lastTimestamp: new Date().getTime()
};
captureData.timer = window.setInterval(
this.captureVideoFrame_.bind(this, captureData), 1000 / RECORD_FPS);
},
/** /**
* Discard current photo and return to the live camera stream. * Discard current photo and return to the live camera stream.
*/ */
...@@ -534,6 +569,27 @@ cr.define('options', function() { ...@@ -534,6 +569,27 @@ cr.define('options', function() {
return canvas.toDataURL('image/png'); return canvas.toDataURL('image/png');
}, },
/**
* Capture next frame of the video being recorded after a takeVideo() call.
* @param {Object} data Property bag with the recorder details.
* @private
*/
captureVideoFrame_: function(data) {
var lastTimestamp = new Date().getTime();
var delayMs = lastTimestamp - data.lastTimestamp;
console.error('Delay: ' + delayMs + ' (' + (1000 / delayMs + ' FPS)'));
data.lastTimestamp = lastTimestamp;
this.captureFrame_(this.cameraVideo_, data.ctx, CAPTURE_SIZE);
data.ctx.translate(0, CAPTURE_SIZE.height);
if (++data.frameNo == RECORD_FRAMES) {
window.clearTimeout(data.timer);
if (data.callback && typeof data.callback == 'function')
data.callback(data.canvas.toDataURL('image/png'));
}
},
/** /**
* Adds new image to the user image grid. * Adds new image to the user image grid.
* @param {string} src Image URL. * @param {string} src Image URL.
......
...@@ -19,15 +19,31 @@ ...@@ -19,15 +19,31 @@
namespace { namespace {
// Animated key is used in user image URL requests to specify that
// animated version of user image is required. Without that key
// non-animated version of user image should be returned.
const char kKeyAnimated[] = "animated";
// Parses the user image URL, which looks like // Parses the user image URL, which looks like
// "chrome://userimage/user@host?key1=value1&...&key_n=value_n", // "chrome://userimage/user@host?key1=value1&...&key_n=value_n",
// to user email. // to user email and optional parameters.
void ParseRequest(const GURL& url, void ParseRequest(const GURL& url,
std::string* email) { std::string* email,
bool* is_image_animated) {
DCHECK(url.is_valid()); DCHECK(url.is_valid());
*email = net::UnescapeURLComponent(url.path().substr(1), *email = net::UnescapeURLComponent(url.path().substr(1),
(net::UnescapeRule::URL_SPECIAL_CHARS | (net::UnescapeRule::URL_SPECIAL_CHARS |
net::UnescapeRule::SPACES)); net::UnescapeRule::SPACES));
std::string url_spec = url.possibly_invalid_spec();
url::Component query = url.parsed_for_possibly_invalid_spec().query;
url::Component key, value;
*is_image_animated = false;
while (ExtractQueryKeyValue(url_spec.c_str(), &query, &key, &value)) {
if (url_spec.substr(key.begin, key.len) == kKeyAnimated) {
*is_image_animated = true;
break;
}
}
} }
} // namespace } // namespace
...@@ -37,10 +53,13 @@ namespace options { ...@@ -37,10 +53,13 @@ namespace options {
base::RefCountedMemory* UserImageSource::GetUserImage( base::RefCountedMemory* UserImageSource::GetUserImage(
const std::string& email, const std::string& email,
bool is_image_animated,
ui::ScaleFactor scale_factor) const { ui::ScaleFactor scale_factor) const {
const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email);
if (user) { if (user) {
if (user->has_raw_image()) { if (user->has_animated_image() && is_image_animated) {
return new base::RefCountedBytes(user->animated_image());
} else if (user->has_raw_image()) {
return new base::RefCountedBytes(user->raw_image()); return new base::RefCountedBytes(user->raw_image());
} else if (user->image_is_stub()) { } else if (user->image_is_stub()) {
return ResourceBundle::GetSharedInstance(). return ResourceBundle::GetSharedInstance().
...@@ -74,14 +93,26 @@ void UserImageSource::StartDataRequest( ...@@ -74,14 +93,26 @@ void UserImageSource::StartDataRequest(
int render_frame_id, int render_frame_id,
const content::URLDataSource::GotDataCallback& callback) { const content::URLDataSource::GotDataCallback& callback) {
std::string email; std::string email;
bool is_image_animated = false;
GURL url(chrome::kChromeUIUserImageURL + path); GURL url(chrome::kChromeUIUserImageURL + path);
ParseRequest(url, &email); ParseRequest(url, &email, &is_image_animated);
callback.Run(GetUserImage(email, ui::SCALE_FACTOR_100P)); callback.Run(GetUserImage(email, is_image_animated, ui::SCALE_FACTOR_100P));
} }
std::string UserImageSource::GetMimeType(const std::string& path) const { std::string UserImageSource::GetMimeType(const std::string& path) const {
// We need to explicitly return a mime type, otherwise if the user tries to // We need to explicitly return a mime type, otherwise if the user tries to
// drag the image they get no extension. // drag the image they get no extension.
std::string email;
bool is_image_animated = false;
GURL url(chrome::kChromeUIUserImageURL + path);
ParseRequest(url, &email, &is_image_animated);
if (is_image_animated) {
const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email);
if (user && user->has_animated_image())
return "image/gif";
}
return "image/png"; return "image/png";
} }
......
...@@ -35,9 +35,11 @@ class UserImageSource : public content::URLDataSource { ...@@ -35,9 +35,11 @@ class UserImageSource : public content::URLDataSource {
const content::URLDataSource::GotDataCallback& callback) OVERRIDE; const content::URLDataSource::GotDataCallback& callback) OVERRIDE;
virtual std::string GetMimeType(const std::string& path) const OVERRIDE; virtual std::string GetMimeType(const std::string& path) const OVERRIDE;
// Returns PNG encoded image for user with specified email. If there's // Returns PNG or GIF (when possible and if |is_image_animated| flag
// is true) encoded image for user with specified email. If there's
// no user with such email, returns the first default image. // no user with such email, returns the first default image.
base::RefCountedMemory* GetUserImage(const std::string& email, base::RefCountedMemory* GetUserImage(const std::string& email,
bool is_image_animated,
ui::ScaleFactor scale_factor) const; ui::ScaleFactor scale_factor) const;
private: private:
......
...@@ -15,6 +15,17 @@ namespace { ...@@ -15,6 +15,17 @@ namespace {
// Default quality for encoding user images. // Default quality for encoding user images.
const int kDefaultEncodingQuality = 90; const int kDefaultEncodingQuality = 90;
bool IsAnimatedImage(const UserImage::RawImage& data) {
const char kGIFStamp[] = "GIF";
const size_t kGIFStampLength = sizeof(kGIFStamp) - 1;
if (data.size() >= kGIFStampLength &&
memcmp(&data[0], kGIFStamp, kGIFStampLength) == 0) {
return true;
}
return false;
}
bool EncodeImageSkia(const gfx::ImageSkia& image, bool EncodeImageSkia(const gfx::ImageSkia& image,
std::vector<unsigned char>* output) { std::vector<unsigned char>* output) {
TRACE_EVENT2("oobe", "EncodeImageSkia", TRACE_EVENT2("oobe", "EncodeImageSkia",
...@@ -47,12 +58,14 @@ UserImage UserImage::CreateAndEncode(const gfx::ImageSkia& image) { ...@@ -47,12 +58,14 @@ UserImage UserImage::CreateAndEncode(const gfx::ImageSkia& image) {
UserImage::UserImage() UserImage::UserImage()
: has_raw_image_(false), : has_raw_image_(false),
has_animated_image_(false),
is_safe_format_(false) { is_safe_format_(false) {
} }
UserImage::UserImage(const gfx::ImageSkia& image) UserImage::UserImage(const gfx::ImageSkia& image)
: image_(image), : image_(image),
has_raw_image_(false), has_raw_image_(false),
has_animated_image_(false),
is_safe_format_(false) { is_safe_format_(false) {
} }
...@@ -60,9 +73,19 @@ UserImage::UserImage(const gfx::ImageSkia& image, ...@@ -60,9 +73,19 @@ UserImage::UserImage(const gfx::ImageSkia& image,
const RawImage& raw_image) const RawImage& raw_image)
: image_(image), : image_(image),
has_raw_image_(false), has_raw_image_(false),
has_animated_image_(false),
is_safe_format_(false) { is_safe_format_(false) {
has_raw_image_ = true; if (IsAnimatedImage(raw_image)) {
raw_image_ = raw_image; has_animated_image_ = true;
animated_image_ = raw_image;
if (EncodeImageSkia(image_, &raw_image_)) {
has_raw_image_ = true;
MarkAsSafe();
}
} else {
has_raw_image_ = true;
raw_image_ = raw_image;
}
} }
UserImage::~UserImage() {} UserImage::~UserImage() {}
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
namespace user_manager { namespace user_manager {
// Wrapper class storing a still image and it's raw representation. Could be // Wrapper class storing a still image and it's raw representation. Could be
// used for storing profile images and user wallpapers. // used for storing profile images (including animated profile images) and user
// wallpapers.
class USER_MANAGER_EXPORT UserImage { class USER_MANAGER_EXPORT UserImage {
public: public:
// TODO(ivankr): replace with RefCountedMemory to prevent copying. // TODO(ivankr): replace with RefCountedMemory to prevent copying.
...@@ -33,6 +34,9 @@ class USER_MANAGER_EXPORT UserImage { ...@@ -33,6 +34,9 @@ class USER_MANAGER_EXPORT UserImage {
explicit UserImage(const gfx::ImageSkia& image); explicit UserImage(const gfx::ImageSkia& image);
// Creates a new instance from a given still frame and raw representation. // Creates a new instance from a given still frame and raw representation.
// |raw_image| can be animated, in which case animated_image() will return the
// original |raw_image| and raw_image() will return the encoded representation
// of |image|.
UserImage(const gfx::ImageSkia& image, const RawImage& raw_image); UserImage(const gfx::ImageSkia& image, const RawImage& raw_image);
virtual ~UserImage(); virtual ~UserImage();
...@@ -46,6 +50,10 @@ class USER_MANAGER_EXPORT UserImage { ...@@ -46,6 +50,10 @@ class USER_MANAGER_EXPORT UserImage {
// Discards the stored raw image, freeing used memory. // Discards the stored raw image, freeing used memory.
void DiscardRawImage(); void DiscardRawImage();
// Optional raw representation of the animated image.
bool has_animated_image() const { return has_animated_image_; }
const RawImage& animated_image() const { return animated_image_; }
// URL from which this image was originally downloaded, if any. // URL from which this image was originally downloaded, if any.
void set_url(const GURL& url) { url_ = url; } void set_url(const GURL& url) { url_ = url; }
GURL url() const { return url_; } GURL url() const { return url_; }
...@@ -62,6 +70,8 @@ class USER_MANAGER_EXPORT UserImage { ...@@ -62,6 +70,8 @@ class USER_MANAGER_EXPORT UserImage {
gfx::ImageSkia image_; gfx::ImageSkia image_;
bool has_raw_image_; bool has_raw_image_;
RawImage raw_image_; RawImage raw_image_;
bool has_animated_image_;
RawImage animated_image_;
GURL url_; GURL url_;
// If image was loaded from the local file, file path is stored here. // If image was loaded from the local file, file path is stored here.
......
...@@ -450,6 +450,27 @@ component("media") { ...@@ -450,6 +450,27 @@ component("media") {
} }
} }
if (is_chromeos) {
# A simple WebM encoder for animated avatars on ChromeOS.
sources += [
"formats/webm/chromeos/ebml_writer.cc",
"formats/webm/chromeos/ebml_writer.h",
"formats/webm/chromeos/webm_encoder.cc",
"formats/webm/chromeos/webm_encoder.h",
]
deps += [
"//third_party/libvpx",
"//third_party/libyuv"
]
# For VaapiVideoEncodeAccelerator.
if (cpu_arch != "arm" && use_x11) {
sources += [
"filters/h264_bitstream_buffer.cc",
"filters/h264_bitstream_buffer.h",
]
}
}
if (!is_ios) { if (!is_ios) {
deps += [ "//third_party/libyuv" ] deps += [ "//third_party/libyuv" ]
} }
......
include_rules = [
"+libyuv",
"+third_party/libvpx",
]
// Copyright 2014 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 "media/formats/webm/chromeos/ebml_writer.h"
#include "media/base/media_export.h"
extern "C" {
#include "third_party/libvpx/source/libvpx/third_party/libmkv/EbmlWriter.h"
EbmlGlobal::EbmlGlobal() {
}
EbmlGlobal::~EbmlGlobal() {
}
// These functions must be in the global namespace and visible to libmkv.
void MEDIA_EXPORT Ebml_Write(EbmlGlobal* glob,
const void* buffer,
unsigned long len) {
glob->write_cb.Run(buffer, len);
}
void MEDIA_EXPORT Ebml_Serialize(EbmlGlobal* glob,
const void* buffer,
int buffer_size,
unsigned long len) {
glob->serialize_cb.Run(buffer, buffer_size, len);
}
} // extern "C"
// Copyright 2014 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 MEDIA_FORMATS_WEBM_CHROMEOS_EBML_WRITER_H_
#define MEDIA_FORMATS_WEBM_CHROMEOS_EBML_WRITER_H_
#include "base/callback.h"
// This struct serves as a bridge betweeen static libmkv interface and Chrome's
// base::Callback. Must be in the global namespace. See EbmlWriter.h.
struct EbmlGlobal {
EbmlGlobal();
~EbmlGlobal();
base::Callback<void(const void* buffer, unsigned long len)> write_cb;
base::Callback<void(const void* buffer, int buffer_size, unsigned long len)>
serialize_cb;
};
#endif // MEDIA_FORMATS_WEBM_CHROMEOS_EBML_WRITER_H_
This diff is collapsed.
// Copyright 2014 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 MEDIA_FORMATS_WEBM_CHROMEOS_WEBM_ENCODER_H_
#define MEDIA_FORMATS_WEBM_CHROMEOS_WEBM_ENCODER_H_
#include <stdio.h>
#include <stack>
#include "base/files/file_path.h"
#include "media/base/media_export.h"
#include "media/formats/webm/chromeos/ebml_writer.h"
extern "C" {
#define VPX_CODEC_DISABLE_COMPAT 1
#include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h"
#include "third_party/libvpx/source/libvpx/vpx/vp8cx.h"
}
class SkBitmap;
namespace base {
class FilePath;
}
namespace media {
namespace chromeos {
// WebM encoder using libvpx. Currently only supports one-pass, constant bitrate
// encoding of short files consisting of a single video track. Seek info and
// cues are not supported, so generated .webm file does not strictly adhere to
// WebM standard (http://www.webmproject.org/code/specs/container/).
class MEDIA_EXPORT WebmEncoder {
public:
// Create new instance for writing to |output_path|. If |realtime| is |true|,
// uses realtime deadline, otherwise - "good quality" deadline.
WebmEncoder(const base::FilePath& output_path, int bitrate, bool realtime);
~WebmEncoder();
// Encodes video from a Nx(N*M) sprite, having M frames of size NxN with FPS
// |fps_n/fps_d|. Must be called on a thread that allows disk IO.
// Returns |true| iff encoding and writing to file is successful.
bool EncodeFromSprite(const SkBitmap& sprite, int fps_n, int fps_d);
private:
// Writes global WebM header and starts a single video track. Returns |false|
// if there was an error opening file for writing.
bool WriteWebmHeader();
// Writes VPX packet to output file.
void WriteWebmBlock(const vpx_codec_cx_pkt_t* packet);
// Finishes video track and closes output file. Returns |false| if there were
// any error during encoding/writing file.
bool WriteWebmFooter();
// Starts a new WebM sub-element of given type. Those can be nested.
void StartSubElement(unsigned long class_id);
// Closes current top-level sub-element.
void EndSubElement();
// libmkv callbacks.
void EbmlWrite(const void* buffer, unsigned long len);
void EbmlSerialize(const void* buffer, int buffer_size, unsigned long len);
template <typename T>
void EbmlSerializeHelper(const T* buffer, unsigned long len);
// Video dimensions and FPS.
size_t width_;
size_t height_;
vpx_rational_t fps_;
// Number of frames in video.
size_t frame_count_;
// VPX config in use.
vpx_codec_enc_cfg_t config_;
// VPX parameters.
int bitrate_;
unsigned long deadline_;
// EbmlWriter context.
EbmlGlobal ebml_writer_;
// Stack with start offsets of currently open sub-elements.
std::stack<long int> ebml_sub_elements_;
base::FilePath output_path_;
FILE* output_;
// True if an error occured while encoding/writing to file.
bool has_errors_;
DISALLOW_COPY_AND_ASSIGN(WebmEncoder);
};
} // namespace chromeos
} // namespace media
#endif // MEDIA_FORMATS_WEBM_CHROMEOS_WEBM_ENCODER_H_
...@@ -650,6 +650,19 @@ ...@@ -650,6 +650,19 @@
'DISABLE_USER_INPUT_MONITOR', 'DISABLE_USER_INPUT_MONITOR',
], ],
}], }],
# A simple WebM encoder for animated avatars on ChromeOS.
['chromeos==1', {
'dependencies': [
'../third_party/libvpx/libvpx.gyp:libvpx',
'../third_party/libyuv/libyuv.gyp:libyuv',
],
'sources': [
'formats/webm/chromeos/ebml_writer.cc',
'formats/webm/chromeos/ebml_writer.h',
'formats/webm/chromeos/webm_encoder.cc',
'formats/webm/chromeos/webm_encoder.h',
],
}],
# For VaapiVideoEncodeAccelerator. # For VaapiVideoEncodeAccelerator.
['target_arch != "arm" and chromeos == 1 and use_x11 == 1', { ['target_arch != "arm" and chromeos == 1 and use_x11 == 1', {
'sources': [ 'sources': [
......
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