Commit 860a9235 authored by Shik Chen's avatar Shik Chen Committed by Commit Bot

CCA: Use the recording start timestamp for file name

This CL removes the renaming behavior for video recording to simplify
the logic, and mitigate thumbnail regeneration timeout issue in Files
app for long video.

Bug: 1058325, 1080869
Test: Verify the file name manually, and pass CCAUIRecordVideo and CCAUIIntent
Change-Id: I074885d95e8cf41d85cf46ef866c47500726708b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2210201
Commit-Queue: Shik Chen <shik@chromium.org>
Commit-Queue: Kuo Jen Wei <inker@chromium.org>
Auto-Submit: Shik Chen <shik@chromium.org>
Reviewed-by: default avatarKuo Jen Wei <inker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770953}
parent 44b29b76
...@@ -206,16 +206,15 @@ export class GalleryButton { ...@@ -206,16 +206,15 @@ export class GalleryButton {
* @override * @override
*/ */
async startSaveVideo() { async startSaveVideo() {
const tempFile = await filesystem.createTempVideoFile(); const file = await filesystem.createVideoFile();
return VideoSaver.createForFile(tempFile); return VideoSaver.createForFile(file);
} }
/** /**
* @override * @override
*/ */
async finishSaveVideo(video, name) { async finishSaveVideo(video) {
const tempFile = await video.endWrite(); const file = await video.endWrite();
const file = await filesystem.saveVideo(tempFile, name);
assert(file !== null); assert(file !== null);
await this.updateCover_(file); await this.updateCover_(file);
} }
......
...@@ -334,9 +334,8 @@ function saveToFile(dir, name, blob) { ...@@ -334,9 +334,8 @@ function saveToFile(dir, name, blob) {
* @return {!Promise<?FileEntry>} Promise for the result. * @return {!Promise<?FileEntry>} Promise for the result.
*/ */
export function saveBlob(blob, filename) { export function saveBlob(blob, filename) {
const dir = externalDir || internalDir; assert(externalDir !== null);
assert(dir !== null); return saveToFile(externalDir, filename, blob);
return saveToFile(dir, filename, blob);
} }
/** /**
...@@ -358,15 +357,14 @@ export function getFileWriter(file) { ...@@ -358,15 +357,14 @@ export function getFileWriter(file) {
} }
/** /**
* Creates a file for saving temporary video recording result. * Creates a file for saving video recording result.
* @return {!Promise<!FileEntry>} Newly created temporary file. * @return {!Promise<!FileEntry>} Newly created video file.
* @throws {Error} If failed to create video temp file. * @throws {Error} If failed to create video file.
*/ */
export async function createTempVideoFile() { export async function createVideoFile() {
const dir = externalDir || internalDir; assert(externalDir !== null);
assert(dir !== null);
const filename = new Filenamer().newVideoName(); const filename = new Filenamer().newVideoName();
const file = await getFile(dir, filename, true); const file = await getFile(externalDir, filename, true);
if (file === null) { if (file === null) {
throw new Error('Failed to create video temp file.'); throw new Error('Failed to create video temp file.');
} }
...@@ -393,30 +391,6 @@ export async function createPrivateTempVideoFile() { ...@@ -393,30 +391,6 @@ export async function createPrivateTempVideoFile() {
return file; return file;
} }
/**
* Saves temporary video file to predefined default location.
* @param {!FileEntry} tempfile Temporary video file to be saved.
* @param {string} filename Filename to be saved.
* @return {!Promise<!FileEntry>} Saved video file.
*/
export async function saveVideo(tempfile, filename) {
const dir = externalDir || internalDir;
assert(dir !== null);
// Non-null version for the Closure Compiler.
const nonNullDir = dir;
// Assuming content of tempfile contains all recorded chunks appended together
// and is a well-formed video. The work needed here is just to move the file
// to the correct directory and rename as the specified filename.
if (tempfile.name === filename) {
return tempfile;
}
return new Promise(
(resolve, reject) =>
tempfile.moveTo(nonNullDir, filename, resolve, reject));
}
/** /**
* Increments the file index of a given file name to avoid name conflicts. * Increments the file index of a given file name to avoid name conflicts.
* @param {string} name File name. * @param {string} name File name.
......
...@@ -28,8 +28,7 @@ export class ResultSaver { ...@@ -28,8 +28,7 @@ export class ResultSaver {
* Saves captured video result. * Saves captured video result.
* @param {!VideoSaver} video Contains the video result to be * @param {!VideoSaver} video Contains the video result to be
* saved. * saved.
* @param {string} name Name of the video to be saved.
* @return {!Promise} * @return {!Promise}
*/ */
async finishSaveVideo(video, name) {} async finishSaveVideo(video) {}
} }
...@@ -361,17 +361,16 @@ export class Camera extends View { ...@@ -361,17 +361,16 @@ export class Camera extends View {
/** /**
* Handles captured video result. * Handles captured video result.
* @param {!VideoResult} result Captured video result. * @param {!VideoResult} result Captured video result.
* @param {string} name Name of the video result to be saved as.
* @return {!Promise} Promise for the operation. * @return {!Promise} Promise for the operation.
* @protected * @protected
*/ */
async doSaveVideo_(result, name) { async doSaveVideo_(result) {
metrics.log( metrics.log(
metrics.Type.CAPTURE, this.facingMode_, result.duration, metrics.Type.CAPTURE, this.facingMode_, result.duration,
result.resolution, metrics.IntentResultType.NOT_INTENT, result.resolution, metrics.IntentResultType.NOT_INTENT,
this.shutterType_); this.shutterType_);
try { try {
await this.resultSaver_.finishSaveVideo(result.videoSaver, name); await this.resultSaver_.finishSaveVideo(result.videoSaver);
} catch (e) { } catch (e) {
toast.show('error_msg_save_file_failed'); toast.show('error_msg_save_file_failed');
throw e; throw e;
......
...@@ -73,9 +73,8 @@ export let CreateVideoSaver; ...@@ -73,9 +73,8 @@ export let CreateVideoSaver;
/** /**
* Callback for saving video capture result. * Callback for saving video capture result.
* param {!VideoResult} Captured video result. * param {!VideoResult} Captured video result.
* param {string} Name of the video result to be saved as.
* return {!Promise} * return {!Promise}
* @typedef {function(!VideoResult, string): !Promise} * @typedef {function(!VideoResult): !Promise}
*/ */
export let DoSaveVideo; export let DoSaveVideo;
...@@ -682,8 +681,7 @@ class Video extends ModeBase { ...@@ -682,8 +681,7 @@ class Video extends ModeBase {
const resolution = new Resolution(settings.width, settings.height); const resolution = new Resolution(settings.width, settings.height);
state.set(PerfEvent.VIDEO_CAPTURE_POST_PROCESSING, true); state.set(PerfEvent.VIDEO_CAPTURE_POST_PROCESSING, true);
try { try {
await this.doSaveVideo_( await this.doSaveVideo_({resolution, duration, videoSaver});
{resolution, duration, videoSaver}, (new Filenamer()).newVideoName());
state.set( state.set(
PerfEvent.VIDEO_CAPTURE_POST_PROCESSING, false, PerfEvent.VIDEO_CAPTURE_POST_PROCESSING, false,
{resolution, facing: this.facing_}); {resolution, facing: this.facing_});
......
...@@ -65,7 +65,7 @@ export class CameraIntent extends Camera { ...@@ -65,7 +65,7 @@ export class CameraIntent extends Camera {
startSaveVideo: async () => { startSaveVideo: async () => {
return await VideoSaver.createForIntent(intent); return await VideoSaver.createForIntent(intent);
}, },
finishSaveVideo: async (video, savedName) => { finishSaveVideo: async (video) => {
this.videoResultFile_ = await video.endWrite(); this.videoResultFile_ = await video.endWrite();
}, },
}); });
...@@ -120,10 +120,10 @@ export class CameraIntent extends Camera { ...@@ -120,10 +120,10 @@ export class CameraIntent extends Camera {
/** /**
* @override * @override
*/ */
async doSaveVideo_(result, name) { async doSaveVideo_(result) {
this.videoResult_ = result; this.videoResult_ = result;
try { try {
await this.resultSaver_.finishSaveVideo(result.videoSaver, name); await this.resultSaver_.finishSaveVideo(result.videoSaver);
} catch (e) { } catch (e) {
toast.show('error_msg_save_file_failed'); toast.show('error_msg_save_file_failed');
throw e; throw e;
......
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