Skip to content

Commit

Permalink
Complex refactoring
Browse files Browse the repository at this point in the history
- Removed BOOST dependency
- Added C++11 dependency
- Basic Android build support (very basic)
  • Loading branch information
h4tr3d committed Dec 4, 2013
1 parent 15bfa90 commit a487798
Show file tree
Hide file tree
Showing 47 changed files with 333 additions and 208 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ qtcreator-build/
qtcreator-build-*/
scripts/valgrind.txt
transcoder-manager-*-win32.zip

build
34 changes: 18 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required (VERSION 2.8)
project(transcoder)
project(AvCpp)

include_directories(.)

Expand All @@ -11,25 +11,27 @@ if(CMAKE_CROSSCOMPILING)
"${CMAKE_EXE_LINKER_FLAGS} -Wl,-subsystem,console -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc")
endif()

set(BOOST_COMPONENTS
system
date_time
filesystem
)
# Boost thread library is different on Win/Linux
if(WIN32)
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} thread_win32)
else()
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} thread)
# C++11
#list(APPEND CMAKE_CXX_FLAGS "-std=c++11")
#set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-std=c++11)
endif()

#set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
# -Weffc++
add_definitions(-DBOOST_THREAD_USE_LIB=1 -D__STDC_CONSTANT_MACROS=1)
# Compiler-specific C++11 activation.
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (NOT (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7))
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 4.7 or greater.")
endif ()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
else ()
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
endif ()

find_package(Threads)
find_package(Boost COMPONENTS ${BOOST_COMPONENTS} REQUIRED)
find_package(PkgConfig)

pkg_check_modules(FFMPEG REQUIRED libavformat libavcodec libswscale libswresample libavutil libavfilter)
Expand Down
1 change: 1 addition & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj
1 change: 1 addition & 0 deletions android/default.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target=android-10
52 changes: 52 additions & 0 deletions android/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := avcpp-android

GLOBAL_C_INCLUDES := \
$(LOCAL_PATH)/../../src

LOCAL_SRC_FILES := \
$(LOCAL_PATH)/../../src/videoframe.cpp \
$(LOCAL_PATH)/../../src/filterbufferref.cpp \
$(LOCAL_PATH)/../../src/filteropaque.cpp \
$(LOCAL_PATH)/../../src/streamcoder.cpp \
$(LOCAL_PATH)/../../src/filter.cpp \
$(LOCAL_PATH)/../../src/filtergraph.cpp \
$(LOCAL_PATH)/../../src/avtime.cpp \
$(LOCAL_PATH)/../../src/codec.cpp \
$(LOCAL_PATH)/../../src/filterinout.cpp \
$(LOCAL_PATH)/../../src/rational.cpp \
$(LOCAL_PATH)/../../src/stream.cpp \
$(LOCAL_PATH)/../../src/avutils.cpp \
$(LOCAL_PATH)/../../src/filters/buffersrc.cpp \
$(LOCAL_PATH)/../../src/filters/buffersink.cpp \
$(LOCAL_PATH)/../../src/containerformat.cpp \
$(LOCAL_PATH)/../../src/filterpad.cpp \
$(LOCAL_PATH)/../../src/frame.cpp \
$(LOCAL_PATH)/../../src/packet.cpp \
$(LOCAL_PATH)/../../src/audiosamples.cpp \
$(LOCAL_PATH)/../../src/videoresampler.cpp \
$(LOCAL_PATH)/../../src/container.cpp \
$(LOCAL_PATH)/../../src/rect.cpp \
$(LOCAL_PATH)/../../src/audioresampler.cpp \
$(LOCAL_PATH)/../../src/filtercontext.cpp

#FFMPEG_INCDIR := $(LOCAL_PATH)/ffmpeg/$(TARGET_ARCH)/include
#FFMPEG_LIBDIR := $(LOCAL_PATH)/ffmpeg/$(TARGET_ARCH)/lib

FFMPEG_INCDIR := $(LOCAL_PATH)/ffmpeg/armeabi-v7a/include
FFMPEG_LIBDIR := $(LOCAL_PATH)/ffmpeg/armeabi-v7a/lib


LOCAL_CXXFLAGS += -I$(FFMPEG_INCDIR)
LOCAL_LDLIBS := -L$(FFMPEG_LIBDIR) -lm

LOCAL_STATIC_LIBRARIES := avformat avcodec swscale swresample avutil avfilter

LOCAL_C_INCLUDES := $(GLOBAL_C_INCLUDES)

include $(BUILD_STATIC_LIBRARY)

11 changes: 11 additions & 0 deletions android/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
APP_OPTIM := release
APP_PLATFORM := android-14
APP_STL := gnustl_static
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -fexceptions
APP_CPPFLAGS += -std=c++11
APP_CPPFLAGS += -D__STDC_CONSTANT_MACROS
#APP_ABI := armeabi armeabi-v7a
APP_ABI := armeabi-v7a
APP_MODULES := avcpp-android
NDK_TOOLCHAIN_VERSION := 4.8
2 changes: 2 additions & 0 deletions android/jni/ffmpeg/armeabi-v7a/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include
lib
2 changes: 0 additions & 2 deletions example/sample-transcode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ list(APPEND AV_TEST_TRANSCODE_HEADERS ${AV_HEADERS})

set(AV_TEST_TRANSCODE_TARGET av-test-transcode)

include_directories(${Boost_INCLUDE_DIRS})
add_executable(${AV_TEST_TRANSCODE_TARGET} ${AV_TEST_TRANSCODE_SOURCES})
target_link_libraries(${AV_TEST_TRANSCODE_TARGET}
${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES}
${FFMPEG_LIBRARIES}
avcpp
)
Expand Down
12 changes: 6 additions & 6 deletions example/sample-transcode/av-transcode.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <iostream>
#include <set>
#include <map>

#include <boost/smart_ptr.hpp>
#include <memory>
#include <functional>

#include "av.h"
#include "ffmpeg.h"
Expand Down Expand Up @@ -425,13 +425,13 @@ int main(int argc, char **argv)
frameref.copyToFrame(outFrame);
if (outFrame)
{
VideoFramePtr outVideoFrame = boost::dynamic_pointer_cast<VideoFrame>(outFrame);
VideoFramePtr outVideoFrame = std::static_pointer_cast<VideoFrame>(outFrame);
outVideoFrame->setStreamIndex(streamMapping[pkt->getStreamIndex()]);
outVideoFrame->setTimeBase(encoder->getTimeBase());
outVideoFrame->setPts(pkt->getTimeBase().rescale(pkt->getPts(), outVideoFrame->getTimeBase()));

outPkt = PacketPtr(new Packet());
stat = encoder->encodeVideo(outPkt, outVideoFrame, boost::bind(formatWriter, writer, _1));
stat = encoder->encodeVideo(outPkt, outVideoFrame, std::bind(formatWriter, writer, std::placeholders::_1));
}
}
}
Expand Down Expand Up @@ -489,7 +489,7 @@ int main(int argc, char **argv)
samplesref.copyToFrame(outFrame);
if (outFrame)
{
AudioSamplesPtr outSamples = boost::dynamic_pointer_cast<AudioSamples>(outFrame);
AudioSamplesPtr outSamples = std::static_pointer_cast<AudioSamples>(outFrame);

outSamples->setTimeBase(encoder->getTimeBase());
outSamples->setFakePts(pkt->getTimeBase().rescale(pkt->getPts(), outSamples->getTimeBase()));
Expand All @@ -502,7 +502,7 @@ int main(int argc, char **argv)


outPkt = PacketPtr(new Packet());
stat = encoder->encodeAudio(outPkt, outSamples, boost::bind(formatWriter, writer, _1));
stat = encoder->encodeAudio(outPkt, outSamples, std::bind(formatWriter, writer, std::placeholders::_1));
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ file(GLOB_RECURSE AV_HEADERS "*.h" "*.hpp")

set(AV_TARGET avcpp)

include_directories(${Boost_INCLUDE_DIRS})

add_library(${AV_TARGET} STATIC ${AV_SOURCES})

target_link_libraries(${AV_TARGET}
${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES}
${FFMPEG_LIBRARIES}
)

Expand Down
2 changes: 2 additions & 0 deletions src/audioresampler.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <cstdio>

#include "audioresampler.h"

namespace av {
Expand Down
6 changes: 4 additions & 2 deletions src/audioresampler.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef AV_AUDIORESAMPLER_H
#define AV_AUDIORESAMPLER_H

#include <functional>

#include "ffmpeg.h"
#include "audiosamples.h"

Expand Down Expand Up @@ -43,8 +45,8 @@ class AudioResampler
AVSampleFormat srcFormat;
};

typedef boost::shared_ptr<AudioResampler> AudioResamplerPtr;
typedef boost::weak_ptr<AudioResampler> AudioResamplerWPtr;
typedef std::shared_ptr<AudioResampler> AudioResamplerPtr;
typedef std::weak_ptr<AudioResampler> AudioResamplerWPtr;

} // namespace av

Expand Down
15 changes: 12 additions & 3 deletions src/audiosamples.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <cassert>
#include <cstdio>
#include <iostream>

#include <boost/format.hpp>

#include "audiosamples.h"

namespace av {
Expand Down Expand Up @@ -159,7 +159,7 @@ bool AudioSamples::isValid() const
return false;
}

boost::shared_ptr<Frame> AudioSamples::clone()
std::shared_ptr<Frame> AudioSamples::clone()
{
FramePtr result(new AudioSamples(*this));
return result;
Expand Down Expand Up @@ -212,12 +212,21 @@ void AudioSamples::setupDataPointers(const AVFrame *frame)
// This is error....
if (size < 0)
{
/*
std::cout << boost::format("Can't allocate memory for audio sample data: "
"empty audio sample (ch:%d, nb_samples:%d, fmt:%d)") %
getChannelsCount() %
frame->nb_samples %
frame->format
<< std::endl;
*/

std::printf("Can't allocate memory for audio sample data: "
"empty audio sample (ch:%d, nb_samples:%d, fmt:%d)",
getChannelsCount(),
frame->nb_samples,
frame->format);

return;
}

Expand Down
8 changes: 5 additions & 3 deletions src/audiosamples.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef AV_AUDIOSAMPLES_H
#define AV_AUDIOSAMPLES_H

#include <memory>

#include "frame.h"

namespace av {
Expand Down Expand Up @@ -37,7 +39,7 @@ class AudioSamples : public Frame
// public virtual
virtual int getSize() const;
virtual bool isValid() const;
virtual boost::shared_ptr<Frame> clone();
virtual std::shared_ptr<Frame> clone();

// Common
// Override this methods: we want to have access to PTS but don't need change it in AVFrame
Expand Down Expand Up @@ -70,8 +72,8 @@ class AudioSamples : public Frame
void init(AVSampleFormat sampleFormat, int samplesCount, int channels, int samplesRate);
};

typedef boost::shared_ptr<AudioSamples> AudioSamplesPtr;
typedef boost::weak_ptr<AudioSamples> AudioSamplesWPtr;
typedef std::shared_ptr<AudioSamples> AudioSamplesPtr;
typedef std::weak_ptr<AudioSamples> AudioSamplesWPtr;

} // namespace av

Expand Down
6 changes: 3 additions & 3 deletions src/avutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void setFFmpegLoggingLevel(const string &level)
{
try
{
setFFmpegLoggingLevel(boost::lexical_cast<int32_t>(level));
setFFmpegLoggingLevel(lexical_cast<int32_t>(level));
}
catch (...)
{}
Expand Down Expand Up @@ -87,13 +87,13 @@ static int avcpp_lockmgr_cb(void **ctx, enum AVLockOp op)
if (!ctx)
return 1;

boost::mutex *mutex = static_cast<boost::mutex*>(*ctx);
std::mutex *mutex = static_cast<std::mutex*>(*ctx);

int ret = 0;
switch (op)
{
case AV_LOCK_CREATE:
mutex = new boost::mutex();
mutex = new std::mutex();
*ctx = mutex;
ret = !!mutex;
break;
Expand Down
27 changes: 24 additions & 3 deletions src/avutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#include <string>
#include <vector>

#include <boost/smart_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include <memory>
#include <mutex>
#include <sstream>
#include <algorithm>

#include "ffmpeg.h"
#include "packet.h"
Expand All @@ -17,6 +18,26 @@
//
namespace av {

template<typename R, typename T>
R lexical_cast(const T& v)
{
R result;
stringstream ss;
ss << v;
ss >> result;
return result;
}

class noncopyable
{
protected:
noncopyable() {}
~noncopyable() {}
private: // emphasize the following members are private
noncopyable( const noncopyable& );
const noncopyable& operator=( const noncopyable& );
};

/**
* This method can be used to turn up or down FFmpeg's logging level.
*
Expand Down
2 changes: 1 addition & 1 deletion src/codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ CodecPtr av::Codec::findDecodingCodec(const char *name)
CodecPtr av::Codec::guessEncodingCodec(const char *name, const char *url, const char *mime)
{
// TODO: need to complete
boost::shared_ptr<Codec> result;
std::shared_ptr<Codec> result;
//CodecID codecId = av_guess_codec();
return result;
}
Expand Down
7 changes: 3 additions & 4 deletions src/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#define CODEC_H

#include <list>

#include <boost/smart_ptr.hpp>
#include <memory>

#include "ffmpeg.h"
#include "rational.h"
Expand All @@ -12,8 +11,8 @@ namespace av {

class Codec;

typedef boost::shared_ptr<Codec> CodecPtr;
typedef boost::weak_ptr<Codec> CodecWPtr;
typedef std::shared_ptr<Codec> CodecPtr;
typedef std::weak_ptr<Codec> CodecWPtr;

class Codec
{
Expand Down
Loading

0 comments on commit a487798

Please sign in to comment.