Commit ce18df34 authored by Linshizhi's avatar Linshizhi

Get input file extension from input file instead of simple

use .aac.
parent f1a4f8aa
#include <stdio.h> #include <stdio.h>
#include <iostream> #include <iostream>
#include <array>
#include <cstdio> #include <cstdio>
#include <fstream> #include <fstream>
#include <algorithm>
#include <dlfcn.h> #include <dlfcn.h>
#include "builtins-encoder.h" #include "builtins-encoder.h"
...@@ -371,9 +373,30 @@ BUILTIN(AddAudioURL) { ...@@ -371,9 +373,30 @@ BUILTIN(AddAudioURL) {
isolate, url_str, Object::ToString(isolate, url)); isolate, url_str, Object::ToString(isolate, url));
std::string url_cppstr = url_str->ToCString().get(); std::string url_cppstr = url_str->ToCString().get();
// Get extension of input file
std::string outpath = std::tmpnam(nullptr); std::string inputExt {}, outpath = std::tmpnam(nullptr);
outpath += ".aac"; std::array<char, 1> search_for = { '.' };
std::array<char, 1> search_for_slash = { '/' };
auto iter = std::find_end(
std::begin(url_cppstr), std::end(url_cppstr),
std::begin(search_for), std::end(search_for));
auto iter_slash = std::find_end(
std::begin(url_cppstr), std::end(url_cppstr),
std::begin(search_for_slash), std::end(search_for_slash));
// If no extension found then leave input file empty
// extension. It's format and codec_type will determine by
// decoder.
// FIXME: Condistion still too weak
if (iter != std::end(url_cppstr)
&& iter_slash != std::end(url_cppstr)
&& iter > iter_slash) {
inputExt = url_cppstr.substr(std::distance(std::begin(url_cppstr), iter));
outpath += inputExt;
}
// Add audio file into AudioEffecter // Add audio file into AudioEffecter
Handle<Object> volume = args.atOrUndefined(isolate, 2); Handle<Object> volume = args.atOrUndefined(isolate, 2);
...@@ -422,6 +445,7 @@ BUILTIN(AddAudioURL) { ...@@ -422,6 +445,7 @@ BUILTIN(AddAudioURL) {
int errorCode = fetchRe(resourcer, url_cppstr.c_str(), outpath.c_str()); int errorCode = fetchRe(resourcer, url_cppstr.c_str(), outpath.c_str());
if (errorCode == 200) { if (errorCode == 200) {
bool isLoop_bool = isLoop_ == 1; bool isLoop_bool = isLoop_ == 1;
// FIXME: Check success of add operation of audio file is required, at least warning.
addInputFileAE(audioEffecter, outpath.c_str(), volume_, strong_end_time_, start_time_, addInputFileAE(audioEffecter, outpath.c_str(), volume_, strong_end_time_, start_time_,
end_time_, delay_, duration_, fade_out_duration_, isLoop_bool); end_time_, delay_, duration_, fade_out_duration_, isLoop_bool);
} }
......
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