-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0069e2
commit 4790f04
Showing
17 changed files
with
348 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
/build | ||
/captures | ||
.externalNativeBuild | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// Created by jasonxiao{github.com/JasonXiao001} on 2019/1/20. | ||
// | ||
|
||
#ifndef EASYPLAYER_COMMON_H | ||
#define EASYPLAYER_COMMON_H | ||
|
||
#define SUCCESS 0 | ||
#define ERROR_ILLEGAL_STATE 1000 | ||
#define ERROR_IO 1001 | ||
|
||
#endif //EASYPLAYER_COMMON_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// Created by jasonxiao{github.com/JasonXiao001} on 2019/1/19. | ||
// | ||
|
||
#include "easy_player.h" | ||
#include "log_util.h" | ||
#include "common.h" | ||
|
||
|
||
EasyPlayer::EasyPlayer() : state_(State::Idle), ic_(nullptr) { | ||
av_log_set_callback(ff_log_callback); | ||
av_log_set_level(AV_LOG_DEBUG); | ||
av_register_all(); | ||
avformat_network_init(); | ||
} | ||
|
||
EasyPlayer::~EasyPlayer() { | ||
if (ic_) { | ||
avformat_free_context(ic_); | ||
ic_ = nullptr; | ||
} | ||
} | ||
|
||
int EasyPlayer::SetDataSource(const std::string &path) { | ||
if (state_ != State::Idle) { | ||
ELOG("illegal state|current:%d", state_); | ||
return ERROR_ILLEGAL_STATE; | ||
} | ||
ILOG("source path:%s", path.c_str()); | ||
int err; | ||
err = avformat_open_input(&ic_, path.c_str(), NULL, NULL); | ||
if (err) { | ||
ELOG("avformat_open_input failed|ret:%d", err); | ||
return ERROR_IO; | ||
} | ||
state_ = State ::Initialized; | ||
return SUCCESS; | ||
} | ||
|
||
int EasyPlayer::PrepareAsync() { | ||
if (state_ != State::Initialized || state_ != State::Stoped) { | ||
ELOG("illegal state|current:%d", state_); | ||
return ERROR_ILLEGAL_STATE; | ||
} | ||
|
||
return SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Created by jasonxiao{github.com/JasonXiao001} on 2019/1/19. | ||
// | ||
|
||
#ifndef EASYPLAYER_EASY_PLAYER_H | ||
#define EASYPLAYER_EASY_PLAYER_H | ||
|
||
#include <thread> | ||
#include <string> | ||
extern "C"{ | ||
#include "libavcodec/avcodec.h" | ||
#include "libavformat/avformat.h" | ||
#include "libswscale/swscale.h" | ||
#include "libswresample/swresample.h" | ||
#include "libavutil/opt.h" | ||
#include "libavutil/imgutils.h" | ||
#include "libavutil/time.h" | ||
#include "libavcodec/avfft.h" | ||
}; | ||
|
||
enum class State { | ||
Idle, | ||
Initialized, | ||
Preparing, | ||
Prepared, | ||
Started, | ||
Paused, | ||
Stoped, | ||
Completed, | ||
End, | ||
Error, | ||
}; | ||
|
||
|
||
class EasyPlayer { | ||
public: | ||
EasyPlayer(); | ||
EasyPlayer(const EasyPlayer&) = delete; | ||
~EasyPlayer(); | ||
int SetDataSource(const std::string &path); | ||
int PrepareAsync(); | ||
|
||
private: | ||
State state_; | ||
AVFormatContext *ic_; | ||
}; | ||
|
||
|
||
#endif //EASYPLAYER_EASY_PLAYER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// Created by jasonxiao{github.com/JasonXiao001} on 2019/1/20. | ||
// | ||
|
||
#include "log_util.h" | ||
#include <string> | ||
#include <sstream> | ||
extern "C" { | ||
#include "libavutil/log.h" | ||
}; | ||
|
||
void ff_log_callback(void* ptr, int level, const char* fmt, va_list vl) { | ||
switch (level) { | ||
case AV_LOG_VERBOSE: | ||
__android_log_vprint(ANDROID_LOG_VERBOSE, FF_LOG_TAG, fmt, vl); | ||
break; | ||
case AV_LOG_DEBUG: | ||
__android_log_vprint(ANDROID_LOG_DEBUG, FF_LOG_TAG, fmt, vl); | ||
break; | ||
case AV_LOG_INFO: | ||
__android_log_vprint(ANDROID_LOG_INFO, FF_LOG_TAG, fmt, vl); | ||
break; | ||
case AV_LOG_WARNING: | ||
__android_log_vprint(ANDROID_LOG_WARN, FF_LOG_TAG, fmt, vl); | ||
break; | ||
case AV_LOG_ERROR: | ||
case AV_LOG_FATAL: | ||
case AV_LOG_PANIC: | ||
__android_log_vprint(ANDROID_LOG_FATAL, FF_LOG_TAG, fmt, vl); | ||
break; | ||
case AV_LOG_QUIET: | ||
__android_log_vprint(ANDROID_LOG_SILENT, FF_LOG_TAG, fmt, vl); | ||
break; | ||
default: | ||
__android_log_vprint(ANDROID_LOG_VERBOSE, FF_LOG_TAG, fmt, vl); | ||
break; | ||
} | ||
} | ||
|
||
void WriteLog(LogLevel level, const char *tag, const char *file_name, const char *func_name, int line, const char *fmt, ...) { | ||
if (level >= MY_LOG_LEVEL) { | ||
std::string file_name_no_path(file_name); | ||
if (file_name_no_path.rfind("\\") != std::string::npos) { | ||
file_name_no_path = file_name_no_path.substr(file_name_no_path.rfind("\\") + 1); | ||
}else { | ||
file_name_no_path = file_name_no_path.substr(file_name_no_path.rfind("/") + 1); | ||
} | ||
char buf[1024]; | ||
std::string log; | ||
va_list ap; | ||
va_start(ap, fmt); | ||
int write_n = vsnprintf(buf, sizeof(buf), fmt, ap); | ||
va_end(ap); | ||
if (write_n >= 0 && write_n < static_cast<int>(sizeof(buf))) { | ||
log = std::string(buf); | ||
}else { | ||
log = "log too long"; | ||
} | ||
std::ostringstream ss; | ||
ss << file_name_no_path << ":" << line << "|" << func_name << ": " << log; | ||
__android_log_write(level, tag, ss.str().c_str()); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Created by jasonxiao{github.com/JasonXiao001} on 2019/1/19. | ||
// | ||
|
||
#ifndef EASYPLAYER_LOG_H | ||
#define EASYPLAYER_LOG_H | ||
|
||
#include <android/log.h> | ||
|
||
enum LogLevel { | ||
kVerbose = 2, | ||
kDebug = 3, | ||
kInfo = 4, | ||
kWarn = 5, | ||
kError = 6, | ||
kOff = 8, | ||
}; | ||
|
||
#ifndef MY_LOG_LEVEL | ||
#define MY_LOG_LEVEL kVerbose | ||
#endif | ||
#ifndef MY_LOG_TAG | ||
#define MY_LOG_TAG "easy_player" | ||
#endif | ||
#ifndef FF_LOG_TAG | ||
#define FF_LOG_TAG "ffmpeg" | ||
#endif | ||
|
||
|
||
void ff_log_callback(void* ptr, int level, const char* fmt, va_list vl); | ||
|
||
void WriteLog(LogLevel level, const char *tag, const char *file_name, const char *func_name, int line, const char *fmt, ...); | ||
|
||
|
||
#define MLOG(level, tag, ...) WriteLog(level, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__); | ||
|
||
#define ELOG(...) MLOG(kError, MY_LOG_TAG, __VA_ARGS__) | ||
#define WLOG(...) MLOG(kWarn, MY_LOG_TAG, __VA_ARGS__) | ||
#define ILOG(...) MLOG(kInfo, MY_LOG_TAG, __VA_ARGS__) | ||
#define DLOG(...) MLOG(kDebug, MY_LOG_TAG, __VA_ARGS__) | ||
#define VLOG(...) MLOG(kVerbose, MY_LOG_TAG, __VA_ARGS__) | ||
|
||
|
||
|
||
|
||
#endif //EASYPLAYER_LOG_H |
Oops, something went wrong.