Added File::Delete as well as deletion of temporary files created by SingleSegmentSegmenter.
Change-Id: Id0aec2f83955f81d2a059c2d077e8381ec7ec1f7
This commit is contained in:
parent
35e033b838
commit
a82bab9f3f
|
@ -18,19 +18,27 @@ namespace media {
|
|||
const char* kLocalFilePrefix = "file://";
|
||||
const char* kUdpFilePrefix = "udp://";
|
||||
|
||||
namespace {
|
||||
|
||||
typedef File* (*FileFactoryFunction)(const char* file_name, const char* mode);
|
||||
typedef bool (*FileDeleteFunction)(const char* file_name);
|
||||
|
||||
struct SupportedTypeInfo {
|
||||
const char* type;
|
||||
size_t type_length;
|
||||
const FileFactoryFunction factory_function;
|
||||
const FileDeleteFunction delete_function;
|
||||
};
|
||||
|
||||
static File* CreateLocalFile(const char* file_name, const char* mode) {
|
||||
File* CreateLocalFile(const char* file_name, const char* mode) {
|
||||
return new LocalFile(file_name, mode);
|
||||
}
|
||||
|
||||
static File* CreateUdpFile(const char* file_name, const char* mode) {
|
||||
bool DeleteLocalFile(const char* file_name) {
|
||||
return LocalFile::Delete(file_name);
|
||||
}
|
||||
|
||||
File* CreateUdpFile(const char* file_name, const char* mode) {
|
||||
if (base::strcasecmp(mode, "r")) {
|
||||
NOTIMPLEMENTED() << "UdpFile only supports read (receive) mode.";
|
||||
return NULL;
|
||||
|
@ -39,10 +47,22 @@ static File* CreateUdpFile(const char* file_name, const char* mode) {
|
|||
}
|
||||
|
||||
static const SupportedTypeInfo kSupportedTypeInfo[] = {
|
||||
{ kLocalFilePrefix, strlen(kLocalFilePrefix), &CreateLocalFile },
|
||||
{ kUdpFilePrefix, strlen(kUdpFilePrefix), &CreateUdpFile },
|
||||
{
|
||||
kLocalFilePrefix,
|
||||
strlen(kLocalFilePrefix),
|
||||
&CreateLocalFile,
|
||||
&DeleteLocalFile
|
||||
},
|
||||
{
|
||||
kUdpFilePrefix,
|
||||
strlen(kUdpFilePrefix),
|
||||
&CreateUdpFile,
|
||||
NULL
|
||||
},
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
File* File::Create(const char* file_name, const char* mode) {
|
||||
for (size_t i = 0; i < arraysize(kSupportedTypeInfo); ++i) {
|
||||
const SupportedTypeInfo& type_info = kSupportedTypeInfo[i];
|
||||
|
@ -66,6 +86,19 @@ File* File::Open(const char* file_name, const char* mode) {
|
|||
return file;
|
||||
}
|
||||
|
||||
bool File::Delete(const char* file_name) {
|
||||
for (size_t i = 0; i < arraysize(kSupportedTypeInfo); ++i) {
|
||||
const SupportedTypeInfo& type_info = kSupportedTypeInfo[i];
|
||||
if (strncmp(type_info.type, file_name, type_info.type_length) == 0) {
|
||||
return type_info.delete_function ?
|
||||
type_info.delete_function(file_name + type_info.type_length) :
|
||||
false;
|
||||
}
|
||||
}
|
||||
// Otherwise we assume it is a local file
|
||||
return DeleteLocalFile(file_name);
|
||||
}
|
||||
|
||||
int64_t File::GetFileSize(const char* file_name) {
|
||||
File* file = File::Open(file_name, "r");
|
||||
if (!file)
|
||||
|
|
|
@ -29,6 +29,11 @@ class File {
|
|||
/// @return A File pointer on success, false otherwise.
|
||||
static File* Open(const char* file_name, const char* mode);
|
||||
|
||||
/// Delete the specified file.
|
||||
/// @param file_name contains the path of the file to be deleted.
|
||||
/// @return true if successful, false otherwise.
|
||||
static bool Delete(const char* file_name);
|
||||
|
||||
/// Flush() and de-allocate resources associated with this file, and
|
||||
/// delete this File object. THIS IS THE ONE TRUE WAY TO DEALLOCATE
|
||||
/// THIS OBJECT.
|
||||
|
|
|
@ -72,5 +72,9 @@ bool LocalFile::Open() {
|
|||
return (internal_file_ != NULL);
|
||||
}
|
||||
|
||||
bool LocalFile::Delete(const char* file_name) {
|
||||
return base::DeleteFile(base::FilePath(file_name), false);
|
||||
}
|
||||
|
||||
} // namespace media
|
||||
} // namespace edash_packager
|
||||
|
|
|
@ -35,6 +35,11 @@ class LocalFile : public File {
|
|||
virtual bool Eof() OVERRIDE;
|
||||
/// @}
|
||||
|
||||
/// Delete a local file.
|
||||
/// @param file_name is the path of the file to be deleted.
|
||||
/// @return true if successful, or false otherwise.
|
||||
static bool Delete(const char* file_name);
|
||||
|
||||
protected:
|
||||
virtual ~LocalFile();
|
||||
|
||||
|
@ -51,4 +56,3 @@ class LocalFile : public File {
|
|||
} // namespace edash_packager
|
||||
|
||||
#endif // PACKAGER_FILE_LOCAL_FILE_H_
|
||||
|
||||
|
|
|
@ -35,7 +35,15 @@ SingleSegmentSegmenter::SingleSegmentSegmenter(const MuxerOptions& options,
|
|||
scoped_ptr<FileType> ftyp,
|
||||
scoped_ptr<Movie> moov)
|
||||
: Segmenter(options, ftyp.Pass(), moov.Pass()) {}
|
||||
SingleSegmentSegmenter::~SingleSegmentSegmenter() {}
|
||||
|
||||
SingleSegmentSegmenter::~SingleSegmentSegmenter() {
|
||||
if (temp_file_)
|
||||
temp_file_.release()->Close();
|
||||
if (!temp_file_name_.empty()) {
|
||||
if (!File::Delete(temp_file_name_.c_str()))
|
||||
LOG(ERROR) << "Unable to delete temporary file " << temp_file_name_;
|
||||
}
|
||||
}
|
||||
|
||||
bool SingleSegmentSegmenter::GetInitRange(size_t* offset, size_t* size) {
|
||||
// In Finalize, ftyp and moov gets written first so offset must be 0.
|
||||
|
|
Loading…
Reference in New Issue