├── .gitignore
├── README.md
├── android
├── AndroidManifest.xml
├── ant.properties
├── jni
│ ├── Android.mk
│ ├── Application.mk
│ ├── h264encoder.cpp
│ ├── h264encoder.h
│ ├── helper.cpp
│ ├── helper.h
│ ├── libapp_build.mk
│ ├── libx264_build.mk
│ ├── main_jni.cpp
│ ├── mediabuffer.cpp
│ ├── mediabuffer.h
│ ├── mediachannel.cpp
│ ├── mediachannel.h
│ ├── rtpstreamer.cpp
│ ├── rtpstreamer.h
│ ├── tcpmediachannel.cpp
│ ├── tcpmediachannel.h
│ ├── udpmediachannel.cpp
│ ├── udpmediachannel.h
│ └── x264
│ │ ├── common
│ │ ├── arm
│ │ │ ├── asm.S
│ │ │ ├── cpu-a.S
│ │ │ ├── dct-a.S
│ │ │ ├── dct.h
│ │ │ ├── deblock-a.S
│ │ │ ├── mc-a.S
│ │ │ ├── mc-c.c
│ │ │ ├── mc.h
│ │ │ ├── pixel-a.S
│ │ │ ├── pixel.h
│ │ │ ├── predict-a.S
│ │ │ ├── predict-c.c
│ │ │ ├── predict.h
│ │ │ ├── quant-a.S
│ │ │ └── quant.h
│ │ ├── bitstream.c
│ │ ├── bitstream.h
│ │ ├── cabac.c
│ │ ├── cabac.h
│ │ ├── common.c
│ │ ├── common.h
│ │ ├── cpu.c
│ │ ├── cpu.h
│ │ ├── dct.c
│ │ ├── dct.h
│ │ ├── deblock.c
│ │ ├── display-x11.c
│ │ ├── display.h
│ │ ├── frame.c
│ │ ├── frame.h
│ │ ├── macroblock.c
│ │ ├── macroblock.h
│ │ ├── mc.c
│ │ ├── mc.h
│ │ ├── mvpred.c
│ │ ├── osdep.c
│ │ ├── osdep.h
│ │ ├── pixel.c
│ │ ├── pixel.h
│ │ ├── ppc
│ │ │ ├── dct.c
│ │ │ ├── dct.h
│ │ │ ├── deblock.c
│ │ │ ├── mc.c
│ │ │ ├── mc.h
│ │ │ ├── pixel.c
│ │ │ ├── pixel.h
│ │ │ ├── ppccommon.h
│ │ │ ├── predict.c
│ │ │ ├── predict.h
│ │ │ ├── quant.c
│ │ │ └── quant.h
│ │ ├── predict.c
│ │ ├── predict.h
│ │ ├── quant.c
│ │ ├── quant.h
│ │ ├── rectangle.c
│ │ ├── rectangle.h
│ │ ├── set.c
│ │ ├── set.h
│ │ ├── sparc
│ │ │ ├── pixel.asm
│ │ │ └── pixel.h
│ │ ├── threadpool.c
│ │ ├── threadpool.h
│ │ ├── visualize.c
│ │ ├── visualize.h
│ │ ├── vlc.c
│ │ ├── win32thread.c
│ │ ├── win32thread.h
│ │ └── x86
│ │ │ ├── bitstream-a.asm
│ │ │ ├── cabac-a.asm
│ │ │ ├── const-a.asm
│ │ │ ├── cpu-a.asm
│ │ │ ├── dct-32.asm
│ │ │ ├── dct-64.asm
│ │ │ ├── dct-a.asm
│ │ │ ├── dct.h
│ │ │ ├── deblock-a.asm
│ │ │ ├── mc-a.asm
│ │ │ ├── mc-a2.asm
│ │ │ ├── mc-c.c
│ │ │ ├── mc.h
│ │ │ ├── pixel-32.asm
│ │ │ ├── pixel-a.asm
│ │ │ ├── pixel.h
│ │ │ ├── predict-a.asm
│ │ │ ├── predict-c.c
│ │ │ ├── predict.h
│ │ │ ├── quant-a.asm
│ │ │ ├── quant.h
│ │ │ ├── sad-a.asm
│ │ │ ├── sad16-a.asm
│ │ │ ├── trellis-64.asm
│ │ │ ├── util.h
│ │ │ ├── x86inc.asm
│ │ │ └── x86util.asm
│ │ ├── config.h
│ │ ├── encoder
│ │ ├── analyse.c
│ │ ├── analyse.h
│ │ ├── cabac.c
│ │ ├── cavlc.c
│ │ ├── encoder.c
│ │ ├── lookahead.c
│ │ ├── macroblock.c
│ │ ├── macroblock.h
│ │ ├── me.c
│ │ ├── me.h
│ │ ├── ratecontrol.c
│ │ ├── ratecontrol.h
│ │ ├── rdo.c
│ │ ├── set.c
│ │ ├── set.h
│ │ └── slicetype.c
│ │ ├── x264.h
│ │ └── x264_config.h
├── project.properties
├── res
│ ├── drawable
│ │ └── icon.png
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── teaonly
│ ├── rtc
│ ├── CameraView.java
│ ├── MainActivity.java
│ └── OverlayView.java
│ └── task
│ ├── GenericTask.java
│ ├── TaskAdapter.java
│ ├── TaskListener.java
│ ├── TaskParams.java
│ └── TaskResult.java
└── desktop
├── Makefile_linux
├── Makefile_osx
├── SimpleRTC.pro
├── app_build.mk
├── datachannel.cpp
├── datachannel.h
├── ezplayer.cpp
├── ezplayer.h
├── ezrender.cpp
├── ezrender.h
├── ffdecoder.cpp
├── ffdecoder.h
├── ffdefine.h
├── libjingle_build.mk
├── libjingle_build_osx.mk
├── main.cpp
├── main_gui.cpp
├── media.cpp
├── media.h
├── mediabuffer.cpp
├── mediabuffer.h
├── player.ui
├── rtpsinker.cpp
├── rtpsinker.h
├── udpdatachannel.cpp
├── udpdatachannel.h
├── videodialog.cpp
├── videodialog.h
├── videowidget.cpp
├── videowidget.h
├── videowidgetsurface.cpp
├── videowidgetsurface.h
└── win
├── inttypes.h
├── libexpat
├── amigaconfig.h
├── ascii.h
├── asciitab.h
├── expat.h
├── expat_external.h
├── iasciitab.h
├── internal.h
├── latin1tab.h
├── macconfig.h
├── nametab.h
├── utf8tab.h
├── winconfig.h
├── xmlparse.c
├── xmlrole.c
├── xmlrole.h
├── xmltok.c
├── xmltok.h
├── xmltok_impl.c
├── xmltok_impl.h
└── xmltok_ns.c
├── libjingle.vcproj
├── simpleRTC.sln
├── simpleRTC.vcproj
└── stdint.h
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Eclipse project files
19 | .classpath
20 | .project
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | AndroidRTC
2 | ==========
3 |
4 | A Simple rtcp/rtp based Android streaming app
5 |
--------------------------------------------------------------------------------
/android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/android/ant.properties:
--------------------------------------------------------------------------------
1 | # This file is used to override default values used by the Ant build system.
2 | #
3 | # This file must be checked into Version Control Systems, as it is
4 | # integral to the build system of your project.
5 |
6 | # This file is only used by the Ant script.
7 |
8 | # You can use this to override default values such as
9 | # 'source.dir' for the location of your java source folder and
10 | # 'out.dir' for the location of your output folder.
11 |
12 | # You can also use it define how the release builds are signed by declaring
13 | # the following properties:
14 | # 'key.store' for the location of your keystore and
15 | # 'key.alias' for the name of the key to use.
16 | # The password will be asked during the build when you use the 'release' target.
17 |
18 |
--------------------------------------------------------------------------------
/android/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH:= $(call my-dir)
2 |
3 | ###########################################################
4 | # building libexpat
5 | #
6 | include $(CLEAR_VARS)
7 | LOCAL_CFLAGS := -DHAVE_MEMMOVE=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1
8 | LOCAL_MODULE := libexpat
9 | LOCAL_SRC_FILES := expat/xmlparse.c \
10 | expat/xmlrole.c \
11 | expat/xmltok.c
12 | include $(BUILD_STATIC_LIBRARY)
13 |
14 | ###########################################################
15 | # building openssl
16 | #
17 | include $(LOCAL_PATH)/openssl/Crypto.mk
18 | include $(LOCAL_PATH)/openssl/Ssl.mk
19 |
20 |
21 | ###########################################################
22 | # building libjingle
23 | #
24 | include $(CLEAR_VARS)
25 | LOCAL_MODULE := libjingle
26 | LOCAL_CPP_EXTENSION := .cc .cpp
27 | LOCAL_CPPFLAGS := -O2 -g3 -Werror -Wall -Wno-switch -Wno-non-virtual-dtor -Wno-ctor-dtor-privacy -fno-rtti -fpic -fno-exceptions
28 | LOCAL_CPPFLAGS += -DLOGGING=1 -DFEATURE_ENABLE_SSL -DHAVE_OPENSSL_SSL_H=1 -DEXPAT_RELATIVE_PATH -DHASHNAMESPACE=__gnu_cxx -DHASH_NAMESPACE=__gnu_cxx -DPOSIX -DDISABLE_DYNAMIC_CAST -D_REENTRANT -DLINUX -DDISABLE_EFFECTS=1 -DANDROID -DARCH_CPU_LITTLE_ENDIAN
29 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/expat $(LOCAL_PATH)/openssl/include
30 | include $(LOCAL_PATH)/libjingle_build.mk
31 |
32 | LOCAL_WHOLE_STATIC_LIBRARIES := libexpat\
33 | libcrypto\
34 | libssl
35 |
36 | LOCAL_SHARED_LIBRARIES := libcutils\
37 | libstlport\
38 | libdl
39 |
40 | LOCAL_LDLIBS := -llog
41 |
42 | include $(BUILD_SHARED_LIBRARY)
43 |
44 | ###########################################################
45 | # building libx264
46 | #
47 | include $(CLEAR_VARS)
48 | LOCAL_CFLAGS := -O3 -Wall -std=gnu99 -fno-fast-math -fPIC -fomit-frame-pointer -fno-tree-vectorize
49 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/x264
50 | LOCAL_MODULE := libx264
51 |
52 | ifeq ($(TARGET_ARCH_ABI),armeabi)
53 | LOCAL_CFLAGS += -DNDK_ARM
54 | endif
55 | ifeq ($(TARGET_ARCH_ABI),x86)
56 | LOCAL_CFLAGS += -DNDK_X86
57 | endif
58 |
59 | include $(LOCAL_PATH)/libx264_build.mk
60 |
61 | include $(BUILD_STATIC_LIBRARY)
62 |
63 | ###########################################################
64 | # building libapp
65 | #
66 | include $(CLEAR_VARS)
67 | LOCAL_MODULE := libapp
68 | LOCAL_CPPFLAGS := -O2 -Wall
69 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/x264
70 | LOCAL_CPP_EXTENSION := .cc .cpp
71 | ifeq ($(TARGET_ARCH_ABI),armeabi)
72 | LOCAL_CFLAGS += -DNDK_ARM
73 | endif
74 | ifeq ($(TARGET_ARCH_ABI),x86)
75 | LOCAL_CFLAGS += -DNDK_X86
76 | endif
77 |
78 | LOCAL_CPPFLAGS += -DLOGGING=1 -DFEATURE_ENABLE_SSL -DHAVE_OPENSSL_SSL_H=1 -DEXPAT_RELATIVE_PATH -DHASHNAMESPACE=__gnu_cxx -DHASH_NAMESPACE=__gnu_cxx -DPOSIX -DDISABLE_DYNAMIC_CAST -D_REENTRANT -DLINUX -DDISABLE_EFFECTS=1 -DANDROID -DARCH_CPU_LITTLE_ENDIAN
79 | include $(LOCAL_PATH)/libapp_build.mk
80 |
81 | LOCAL_WHOLE_STATIC_LIBRARIES := libx264
82 | LOCAL_SHARED_LIBRARIES := libjingle\
83 | libcutils\
84 | libstlport\
85 | libdl
86 | LOCAL_LDLIBS := -llog
87 | include $(BUILD_SHARED_LIBRARY)
88 |
--------------------------------------------------------------------------------
/android/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_PLATFORM := android-8
2 | APP_STL := stlport_static
3 | APP_ABI := armeabi x86
4 |
--------------------------------------------------------------------------------
/android/jni/h264encoder.cpp:
--------------------------------------------------------------------------------
1 | #include "helper.h"
2 | #include "h264encoder.h"
3 |
4 | enum {
5 | MSG_START_ENCODER,
6 | };
7 |
8 | H264Encoder::H264Encoder(talk_base::Thread* thread) {
9 | encoding_thread_ = thread;
10 | x264_hdl_ = NULL;
11 | ppIndex = -1;
12 | }
13 |
14 | H264Encoder::~H264Encoder() {
15 | if ( x264_hdl_ != NULL) {
16 | Release();
17 | }
18 | }
19 |
20 | void H264Encoder::OnMessage(talk_base::Message *msg) {
21 | if ( msg->message_id == MSG_START_ENCODER) {
22 | doEncoding();
23 | }
24 | }
25 |
26 | int H264Encoder::Prepare(const MediaDescription& desc) {
27 | if ( desc.isVideo == false)
28 | return -1;
29 |
30 | int wid = desc.width;
31 | int hei = desc.height;
32 |
33 | // 0. building a default encoder parameters.
34 | x264_param_default_preset(&x264_opt_, "ultrafast", "zerolatency");
35 | x264_opt_.rc.i_rc_method = X264_RC_CRF;
36 | x264_opt_.rc.i_bitrate = 512;
37 | x264_opt_.i_nal_hrd = X264_NAL_HRD_CBR;
38 | //x264_param_default(&opt);
39 |
40 | // 1. Setting the fields of parameter struct
41 | x264_opt_.i_width = wid;
42 | x264_opt_.i_height = hei;
43 | //opt.i_slice_count = 5;
44 | //opt.b_intra_refresh = 1;
45 |
46 | // 3. Prepare the output buffer and target file
47 | x264_picture_alloc(&x264_picin_[0], X264_CSP_NV12, x264_opt_.i_width, x264_opt_.i_height);
48 | x264_picture_alloc(&x264_picin_[1], X264_CSP_NV12, x264_opt_.i_width, x264_opt_.i_height);
49 | x264_picture_alloc(&x264_picout_, X264_CSP_NV12, x264_opt_.i_width, x264_opt_.i_height);
50 | ppIndex = -1;
51 |
52 | // 4. Building the encoder handler
53 | x264_hdl_ = x264_encoder_open(&x264_opt_);
54 | x264_encoder_parameters(x264_hdl_, &x264_opt_);
55 |
56 | return 0;
57 | }
58 |
59 | int H264Encoder::Release() {
60 | if (x264_hdl_ ) {
61 | encoding_thread_->Clear(this);
62 | //x264_picture_clean(&x264_picin_);
63 | //x264_picture_clean(&x264_picout_);
64 | x264_encoder_close(x264_hdl_);
65 | x264_hdl_ = NULL;
66 | }
67 |
68 | return 0;
69 | }
70 |
71 | int H264Encoder::EncodePicture(unsigned char *yuv) {
72 | if ( x264_hdl_ == NULL)
73 | return -1;
74 |
75 | encoding_thread_->Clear(this);
76 |
77 | // FIXME: NV21 ---> NV12
78 | int width = x264_opt_.i_width;
79 | int height = x264_opt_.i_height;
80 | if ( ppIndex == -1 ) {
81 | ppIndex = 0;
82 | memcpy(x264_picin_[ppIndex].img.plane[0], yuv, width*height);
83 | memcpy(x264_picin_[ppIndex].img.plane[1], yuv + width*height - 1, width*height/2);
84 | //memcpy(x264_picin_[ppIndex].img.plane[2], yuv + width*height + width*height/4, width*height/4);
85 | } else {
86 | int index = 1 - ppIndex;
87 | memcpy(x264_picin_[index].img.plane[0], yuv, width*height);
88 | memcpy(x264_picin_[index].img.plane[1], yuv + width*height - 1, width*height/2);
89 | //memcpy(x264_picin_[index].img.plane[2], yuv + width*height + width*height/4, width*height/4);
90 | }
91 |
92 | encoding_thread_->Post(this, MSG_START_ENCODER);
93 |
94 | return 0;
95 | }
96 |
97 | void H264Encoder::doEncoding() {
98 | static int count = 0;
99 | // encoding current picture
100 | int nals;
101 | x264_nal_t *nal_pointer;
102 |
103 | /*
104 | if ( count % 100) {
105 | x264_picin_[ppIndex].i_type = X264_TYPE_IDR;
106 | } else {
107 | x264_picin_[ppIndex].i_type = X264_TYPE_AUTO;
108 | }
109 | */
110 |
111 | x264_encoder_encode(x264_hdl_, &nal_pointer, &nals, &x264_picin_[ppIndex], &x264_picout_);
112 |
113 | // fetching the current data
114 | for ( int i = 0; i < nals; i++) {
115 | if( nal_pointer[i].i_type != 6)
116 | SignalCodedNAL(this, &nal_pointer[i], 0);
117 | }
118 |
119 | ppIndex = 1 - ppIndex;
120 | count ++;
121 | }
122 |
123 |
124 |
--------------------------------------------------------------------------------
/android/jni/h264encoder.h:
--------------------------------------------------------------------------------
1 | #ifndef _H264ENCODER_H_
2 | #define _H264ENCODER_H_
3 |
4 | #include "talk/base/sigslot.h"
5 | #include "talk/base/thread.h"
6 | #include "talk/base/messagequeue.h"
7 | #include "talk/base/criticalsection.h"
8 | #include "talk/base/buffer.h"
9 | #include "helper.h"
10 |
11 | #include
12 | #include
13 | extern "C" {
14 | #include
15 | }
16 |
17 | class H264Encoder : public sigslot::has_slots<>, public talk_base::MessageHandler {
18 | public:
19 | H264Encoder(talk_base::Thread* thread);
20 | ~H264Encoder();
21 |
22 | int Prepare(const MediaDescription& desc);
23 | int EncodePicture(unsigned char *yuv);
24 | int Release();
25 |
26 | sigslot::signal3 SignalCodedNAL;
27 |
28 | protected:
29 | virtual void OnMessage(talk_base::Message *msg);
30 | void doEncoding();
31 |
32 | private:
33 | talk_base::CriticalSection mutex_;
34 | unsigned int pciture_enc_;
35 | int ppIndex;
36 |
37 | talk_base::Thread *encoding_thread_;
38 | x264_param_t x264_opt_;;
39 | x264_t *x264_hdl_;
40 |
41 | x264_picture_t x264_picin_[2];
42 |
43 | x264_picture_t x264_picout_;
44 | };
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/android/jni/helper.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "helper.h"
9 |
10 | using namespace std;
11 |
12 | vector SplitString(const string& s, const string& delim, const bool keep_empty = false) {
13 | vector result;
14 | if (delim.empty()) {
15 | result.push_back(s);
16 | return result;
17 | }
18 | string::const_iterator substart = s.begin(), subend;
19 | while (true) {
20 | subend = search(substart, s.end(), delim.begin(), delim.end());
21 | string temp(substart, subend);
22 | if (keep_empty || !temp.empty()) {
23 | result.push_back(temp);
24 | }
25 | if (subend == s.end()) {
26 | break;
27 | }
28 | substart = subend + delim.size();
29 | }
30 | return result;
31 | }
32 |
33 | bool MediaURL::Parse(const std::string &url) {
34 | proto = "";
35 | location = "";
36 | resource = "";
37 |
38 | vector sub_strs;
39 | string temp;
40 |
41 | sub_strs = SplitString(url, "://");
42 | if ( sub_strs.size() != 2) {
43 | return false;
44 | }
45 | proto = sub_strs[0];
46 | temp = sub_strs[1];
47 |
48 | sub_strs = SplitString(temp, ":"); //is TCP channel , get port number
49 | if(sub_strs.size() == 2) {
50 | location = sub_strs[0];
51 | resource = sub_strs[1];
52 | return true;
53 | }
54 |
55 | sub_strs = SplitString(temp, "/");
56 | if(sub_strs.size() == 2) {
57 | location = sub_strs[0];
58 | resource = sub_strs[1];
59 | return true;
60 | }
61 |
62 | return false;
63 | }
64 |
65 | bool MediaDescription::Parse(const std::string &desc) {
66 | isVideo = false;
67 | isAudio = false;
68 |
69 | vector sub_strs;
70 | string temp;
71 |
72 | sub_strs = SplitString(desc, ":");
73 | if ( sub_strs.size() < 3) {
74 | return false;
75 | }
76 |
77 | if ( sub_strs[0] == "video" && sub_strs.size() == 4)
78 | isVideo = true;
79 | else if ( sub_strs[0] == "audio" && sub_strs.size() == 3)
80 | isAudio = true;
81 | else
82 | return false;
83 |
84 | codec = sub_strs[1];
85 |
86 | if ( isAudio) {
87 | sample = atoi( sub_strs[2].c_str() );
88 | return true;
89 | } else {
90 | width = atoi( sub_strs[2].c_str() );
91 | height = atoi( sub_strs[3].c_str() );
92 | return true;
93 | }
94 |
95 | return false;
96 | }
97 |
--------------------------------------------------------------------------------
/android/jni/helper.h:
--------------------------------------------------------------------------------
1 | #ifndef _HELPER_H_
2 | #define _HELPER_H_
3 |
4 | #include
5 | #include
6 |
7 | #ifdef ANDROID
8 | #include
9 | #include
10 |
11 | #define LOG_TAG "TEAONLY"
12 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
13 | #else
14 | #define LOGD(...)
15 | #endif
16 |
17 | /*
18 | tcp://10.10.10.10:342
19 | proto tcp
20 | location 10.10.10.10
21 | resource 342
22 |
23 | p2p://xxx@xxx.com/pc
24 | proto p2p
25 | location xxx@xxx.com
26 | resource pc
27 |
28 | */
29 | class MediaURL {
30 | public:
31 | bool Parse(const std::string &url);
32 | std::string proto;
33 | std::string location;
34 | std::string resource;
35 | std::string target;
36 | };
37 |
38 |
39 | /*
40 | video:h264:wid:hei
41 |
42 | audio:g711:8000
43 | */
44 | class MediaDescription {
45 | public:
46 | bool Parse(const std::string& description);
47 | bool isVideo;
48 | bool isAudio;
49 | std::string codec;
50 | unsigned int width;
51 | unsigned int height;
52 | unsigned int sample;
53 | };
54 |
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/android/jni/libapp_build.mk:
--------------------------------------------------------------------------------
1 | LOCAL_SRC_FILES += \
2 | talk/session/phone/rtputils.cc\
3 | main_jni.cpp \
4 | helper.cpp \
5 | h264encoder.cpp \
6 | mediachannel.cpp \
7 | mediabuffer.cpp \
8 | tcpmediachannel.cpp \
9 | udpmediachannel.cpp \
10 | rtpstreamer.cpp
11 |
12 |
--------------------------------------------------------------------------------
/android/jni/libx264_build.mk:
--------------------------------------------------------------------------------
1 | LOCAL_SRC_FILES += x264/common/mc.c x264/common/predict.c x264/common/pixel.c x264/common/macroblock.c \
2 | x264/common/frame.c x264/common/dct.c x264/common/cpu.c x264/common/cabac.c \
3 | x264/common/common.c x264/common/osdep.c x264/common/rectangle.c \
4 | x264/common/set.c x264/common/quant.c x264/common/deblock.c x264/common/vlc.c \
5 | x264/common/mvpred.c x264/common/bitstream.c \
6 | x264/encoder/analyse.c x264/encoder/me.c x264/encoder/ratecontrol.c \
7 | x264/encoder/set.c x264/encoder/macroblock.c x264/encoder/cabac.c \
8 | x264/encoder/cavlc.c x264/encoder/encoder.c x264/encoder/lookahead.c
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/android/jni/main_jni.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "talk/base/thread.h"
3 | #include "helper.h"
4 | #include "rtpstreamer.h"
5 |
6 | #define JNIDEFINE(fname) Java_teaonly_rtc_MainActivity_##fname
7 |
8 | extern "C" {
9 | JNIEXPORT jint JNICALL JNIDEFINE(nativeStart)(JNIEnv* env, jclass clz, jstring remote, jstring description);
10 | JNIEXPORT jint JNICALL JNIDEFINE(nativeStop)(JNIEnv* env, jclass clz);
11 |
12 | JNIEXPORT jint JNICALL JNIDEFINE(nativePushFrame)(JNIEnv* env, jclass clz, jbyteArray yuvData);
13 | }
14 |
15 | static std::string convert_jstring(JNIEnv *env, const jstring &js) {
16 | static char outbuf[1024];
17 | std::string str;
18 |
19 | int len = env->GetStringLength(js);
20 | env->GetStringUTFRegion(js, 0, len, outbuf);
21 |
22 | str = outbuf;
23 | return str;
24 | }
25 |
26 |
27 | //*************************************
28 | // Gloal definement
29 | //*************************************
30 |
31 | RtpStreamer *streamer = NULL;
32 | talk_base::Thread *streaming_thread = NULL;
33 | talk_base::Thread *encoding_thread = NULL;
34 |
35 | JNIEXPORT jint JNICALL JNIDEFINE(nativeStart)(JNIEnv* env, jclass clz, jstring jremote, jstring jdescription) {
36 | std::string remote = convert_jstring(env, jremote);
37 | std::string description = convert_jstring(env, jdescription);
38 |
39 | if ( streaming_thread == NULL) {
40 | streaming_thread = new talk_base::Thread();
41 | streaming_thread->Start();
42 | }
43 |
44 | if ( encoding_thread == NULL) {
45 | encoding_thread = new talk_base::Thread();
46 | encoding_thread->Start();
47 | }
48 |
49 | streamer = new RtpStreamer(streaming_thread, encoding_thread);
50 | int ret = streamer->StartStreaming(remote, description, 0x19791010);
51 |
52 | if ( ret < 0) {
53 | delete streamer;
54 | streamer = NULL;
55 | }
56 |
57 | return ret;
58 | }
59 |
60 | JNIEXPORT jint JNICALL JNIDEFINE(nativeStop)(JNIEnv* env, jclass clz) {
61 |
62 | streamer->StopStreaming();
63 | delete streamer;
64 | streamer = NULL;
65 |
66 | return 0;
67 | }
68 |
69 | JNIEXPORT jint JNICALL JNIDEFINE(nativePushFrame)(JNIEnv* env, jclass clz, jbyteArray yuvData) {
70 | if ( streamer != NULL) {
71 | jbyte* cameraFrame= env->GetByteArrayElements(yuvData, NULL);
72 | int ret = streamer->ProvideCameraFrame((unsigned char *)cameraFrame);
73 | env->ReleaseByteArrayElements(yuvData, cameraFrame, JNI_ABORT);
74 | return ret;
75 | }
76 | return -1;
77 | }
78 |
--------------------------------------------------------------------------------
/android/jni/mediabuffer.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "helper.h"
3 | #include "mediabuffer.h"
4 |
5 |
6 | MediaBuffer::MediaBuffer(const unsigned int pkg_number,
7 | const unsigned int pkg_size) {
8 | MediaPackage *pkg;
9 |
10 | pkg_size_ = pkg_size;
11 |
12 | for(unsigned int i = 0; i < pkg_number; i++) {
13 | pkg = new MediaPackage(pkg_size_);
14 | pkg_pool_.push_back(pkg);
15 | }
16 | pkg_released = new MediaPackage(pkg_size_);
17 | pkg_released->length = 0;
18 | pkg_seq_ = 0;
19 |
20 | }
21 |
22 | MediaBuffer::~MediaBuffer(){
23 | MediaPackage *pkg;
24 | for(unsigned int i = 0; i < pkg_pool_.size(); i++) {
25 | pkg = pkg_pool_[i];
26 | delete pkg;
27 | }
28 | pkg_pool_.clear();
29 |
30 | delete pkg_released;
31 | }
32 |
33 | void MediaBuffer::Reset() {
34 | MediaPackage *pkg;
35 |
36 | while(!buffer_.empty()) {
37 | pkg = buffer_.front();
38 | buffer_.pop_front();
39 | pkg_pool_.push_back(pkg);
40 | }
41 | buffer_.clear();
42 |
43 | pkg_seq_ = 0;
44 | pkg_released->length = 0;
45 | }
46 |
47 | bool MediaBuffer::PushBuffer(const unsigned char *d, const unsigned int len) {
48 | MediaPackage *pkg = NULL;
49 | pkg_seq_ ++;
50 |
51 | // check memory space.
52 | if ( len > pkg_size_ ) {
53 | return false;
54 | }
55 |
56 | if ( pkg_pool_.size() == 0) {
57 | return false;
58 | }
59 |
60 | // this is valid push to buffer
61 | {
62 | talk_base::CritScope lock(&mutex_);
63 | pkg = pkg_pool_.back();
64 | pkg_pool_.pop_back();
65 | }
66 | pkg->length = len;
67 | pkg->seq = pkg_seq_;
68 |
69 | memcpy(pkg->data_, d, len);
70 | pkg->data = pkg->data_;
71 | {
72 | talk_base::CritScope lock(&mutex_);
73 | buffer_.push_back(pkg);
74 | }
75 | return true;
76 |
77 | }
78 |
79 | bool MediaBuffer::PullBuffer() {
80 | std::list *pBuffer;
81 | std::vector *pPool;
82 | pBuffer = &buffer_;
83 | pPool = &pkg_pool_;
84 |
85 | MediaPackage *pkg;
86 | {
87 | talk_base::CritScope lock(&mutex_);
88 |
89 | if (pBuffer->size() == 0)
90 | return false;
91 |
92 | pkg = pBuffer->front();
93 | pBuffer->pop_front();
94 | }
95 |
96 | pkg_released->seq = pkg->seq;
97 | pkg_released->length = pkg->length;
98 | memcpy(pkg_released->data_, pkg->data_, pkg_released->length);
99 | pkg_released->data = pkg_released->data_;
100 |
101 | {
102 | talk_base::CritScope lock(&mutex_);
103 | pPool->push_back(pkg);
104 | }
105 |
106 | return true;
107 | }
108 |
109 | MediaPackage * MediaBuffer::Released() {
110 | return pkg_released;
111 | }
112 |
--------------------------------------------------------------------------------
/android/jni/mediabuffer.h:
--------------------------------------------------------------------------------
1 | #ifndef _MEDIABUFFER_H_
2 | #define _MEDIABUFFER_H_
3 |
4 | #include
5 | #include
6 | #include "talk/base/sigslot.h"
7 | #include "talk/base/criticalsection.h"
8 |
9 | const int MUX_OFFSET = 32;
10 |
11 | struct MediaPackage{
12 | public:
13 | MediaPackage(const unsigned int size) {
14 | data_ = new unsigned char[size + MUX_OFFSET];
15 | data_ += MUX_OFFSET;
16 | };
17 | ~MediaPackage() {
18 | if ( data != NULL) {
19 | data_ = data_ - MUX_OFFSET;
20 | delete data_;
21 | }
22 | }
23 |
24 | unsigned char *data_;
25 | unsigned char *data;
26 | unsigned int length;
27 | unsigned int seq;
28 | };
29 |
30 | class MediaBuffer: public sigslot::has_slots<> {
31 | public:
32 | MediaBuffer(const unsigned int num, const unsigned int size);
33 | ~MediaBuffer();
34 | void Reset();
35 |
36 | // access from diffrent threads, they are safe.
37 | bool PushBuffer(const unsigned char *d, const unsigned int len);
38 | bool PullBuffer();
39 | MediaPackage *Released();
40 |
41 | unsigned int BufferSize(){
42 | return buffer_.size();
43 | }
44 |
45 | private:
46 | unsigned int pkg_size_;
47 | unsigned int pkg_seq_;
48 |
49 | std::list buffer_;
50 | std::vector pkg_pool_;
51 | MediaPackage *pkg_released;
52 |
53 | talk_base::CriticalSection mutex_;
54 | };
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/android/jni/mediachannel.cpp:
--------------------------------------------------------------------------------
1 | #include "tcpmediachannel.h"
2 | #include "udpmediachannel.h"
3 |
4 | MediaChannel * CreateChannel(const std::string &type, void *priv) {
5 | if ( type == "tcp" ) {
6 | return new TcpMediaChannel();
7 | } else if ( type == "udp" ) {
8 | return new UdpMediaChannel();
9 | }
10 |
11 | return NULL;
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/android/jni/mediachannel.h:
--------------------------------------------------------------------------------
1 | #ifndef _MEDIACHANNEL_H_
2 | #define _MEDIACHANNEL_H_
3 |
4 | #include "helper.h"
5 | #include "talk/base/sigslot.h"
6 | #include "talk/base/thread.h"
7 |
8 | class MediaChannel : public sigslot::has_slots<> {
9 | public:
10 | MediaChannel(){
11 | is_ready_ = false;
12 | }
13 | virtual ~MediaChannel(){};
14 |
15 | virtual void Connect(const MediaURL &url) = 0;
16 | virtual int PushData(const unsigned char * data, size_t len) = 0;
17 | virtual int Close() = 0;
18 | virtual bool IsReady() {
19 | return is_ready_;
20 | }
21 |
22 | sigslot::signal2 SignalChannelOpened;
23 | sigslot::signal1 SignalChannelClosed;
24 | sigslot::signal3 SignalDataRead;
25 |
26 | protected:
27 | bool is_ready_;
28 | };
29 |
30 | MediaChannel * CreateChannel(const std::string &type, void *priv);
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/android/jni/rtpstreamer.h:
--------------------------------------------------------------------------------
1 | #ifndef _RTPSTREAMER_H_
2 | #define _RTPSTREAMER_H_
3 |
4 | #include "helper.h"
5 | #include "talk/base/sigslot.h"
6 | #include "talk/base/thread.h"
7 | #include "talk/base/messagequeue.h"
8 | #include "talk/base/criticalsection.h"
9 | #include "talk/base/buffer.h"
10 |
11 | #include
12 | #include
13 | extern "C" {
14 | #include
15 | }
16 |
17 |
18 | class MediaChannel;
19 | class H264Encoder;
20 | class MediaBuffer;
21 |
22 | class RtpStreamer: public sigslot::has_slots<>, public talk_base::MessageHandler {
23 | public:
24 | RtpStreamer(talk_base::Thread* sreaming_thread, talk_base::Thread* encoding_thread);
25 | ~RtpStreamer();
26 |
27 | int StartStreaming(const std::string& url, const std::string& description, const unsigned int& ssrc);
28 | int ProvideCameraFrame(unsigned char *yuvData);
29 | int StopStreaming();
30 |
31 | sigslot::signal2 SignalStreamingBegin;
32 | sigslot::signal1 SignalStreamingEnd;
33 |
34 | protected:
35 | virtual void OnMessage(talk_base::Message *msg);
36 | void OnCodedNAL(H264Encoder* enc, x264_nal_t* nal, const unsigned int& ts);
37 |
38 | void OnChannelOpened(MediaChannel *ch, const bool& isOK);
39 | void OnChannelClosed(MediaChannel *ch);
40 | void OnChannelDataRead(MediaChannel *ch, const unsigned char* data, const unsigned int& length);
41 |
42 | void doConnect();
43 | void doStreaming();
44 |
45 | private:
46 | enum StreamingState{
47 | STATE_IDLE,
48 | STATE_CONNECTING,
49 | STATE_STREAMING
50 | };
51 |
52 | StreamingState state_;
53 | MediaChannel* channel_;
54 | H264Encoder* encoder_;
55 | talk_base::Thread *streaming_thread_;
56 | talk_base::Thread *encoding_thread_;
57 |
58 | MediaBuffer *buffer_;
59 | MediaURL url_;
60 | MediaDescription description_;
61 | unsigned int rtpSSRC_;
62 | unsigned short rtpSeq_;
63 | };
64 |
65 |
66 | #endif
67 |
68 |
--------------------------------------------------------------------------------
/android/jni/tcpmediachannel.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "talk/base/socketstream.h"
4 | #include "talk/base/asyncsocket.h"
5 | #include "tcpmediachannel.h"
6 | #include "helper.h"
7 |
8 | TcpMediaChannel::TcpMediaChannel() {
9 | tcp_socket_ = NULL;
10 | }
11 |
12 | TcpMediaChannel::~TcpMediaChannel() {
13 | Close();
14 | }
15 |
16 |
17 | int TcpMediaChannel::Close(){
18 | if( tcp_socket_) {
19 | tcp_socket_->SignalCloseEvent.disconnect(this);
20 | tcp_socket_->SignalConnectEvent.disconnect(this);
21 | tcp_socket_->Close();
22 | delete tcp_socket_;
23 | tcp_socket_ = NULL;
24 | }
25 | return 0;
26 | }
27 |
28 | void TcpMediaChannel::createSocket() {
29 | talk_base::Thread* pth = talk_base::Thread::Current();
30 | talk_base::AsyncSocket* socket =
31 | pth->socketserver()->CreateAsyncSocket(SOCK_STREAM);
32 | tcp_socket_ = socket;
33 | assert(tcp_socket_);
34 | tcp_socket_->SignalConnectEvent.connect(this, &TcpMediaChannel::OnConnectEvent);
35 | tcp_socket_->SignalCloseEvent.connect(this, &TcpMediaChannel::OnCloseEvent);
36 | tcp_socket_->SignalReadEvent.connect(this, &TcpMediaChannel::OnReadEvent);
37 | }
38 |
39 | int TcpMediaChannel::doConnect() {
40 | int port;
41 | std::string remote_addr;
42 | remote_addr = my_url_.location;
43 | port = atoi( my_url_.resource.c_str());
44 |
45 | talk_base::SocketAddress addr(remote_addr, port);
46 | LOGD( addr.ToString().c_str());
47 | if (tcp_socket_->Connect(addr) < 0) {
48 | if ( tcp_socket_->IsBlocking() ) {
49 | return 0;
50 | }
51 | return -1;
52 | }
53 | return 1;
54 | }
55 |
56 | void TcpMediaChannel::Connect(const MediaURL& url) {
57 | my_url_ = url;
58 | is_ready_ = false;
59 | Close();
60 |
61 | createSocket();
62 | int ret = doConnect();
63 |
64 | if ( ret < 0) {
65 | Close();
66 | SignalChannelOpened(this, false);
67 | }
68 | }
69 |
70 | int TcpMediaChannel::PushData(const unsigned char *data, size_t len) {
71 | if ( tcp_socket_ == NULL)
72 | return -1;
73 |
74 | if ( tcp_socket_->GetState() == talk_base::Socket::CS_CONNECTING)
75 | return 0;
76 |
77 | int result = tcp_socket_->Send(data, len);
78 | if (result < 0) {
79 | if (tcp_socket_->IsBlocking())
80 | return 0;
81 | OnCloseEvent(tcp_socket_, errno);
82 | return -1;
83 | }
84 |
85 | return result;
86 | }
87 |
88 | void TcpMediaChannel::OnConnectEvent(talk_base::AsyncSocket* socket) {
89 | assert(socket == tcp_socket_);
90 | LOGD("Detecting OnConnectEvent!\n");
91 | if ( tcp_socket_->GetState() == talk_base::Socket::CS_CONNECTED) {
92 | if ( is_ready_ == false) {
93 | is_ready_ = true;
94 | SignalChannelOpened(this, true);
95 | return;
96 | }
97 | }
98 |
99 | if ( tcp_socket_->GetState() == talk_base::Socket::CS_CLOSED) {
100 | if ( is_ready_ == false) {
101 | Close();
102 | SignalChannelOpened(this, false);
103 | }else {
104 | is_ready_ = false;
105 | Close();
106 | SignalChannelClosed(this);
107 | }
108 | }
109 | }
110 |
111 |
112 | void TcpMediaChannel::OnReadEvent(talk_base::AsyncSocket* socket) {
113 | assert(socket == tcp_socket_);
114 |
115 | unsigned char temp[2048];
116 | int ret = tcp_socket_->Recv(temp, sizeof(temp) - 1);
117 | if (ret > 0) {
118 | SignalDataRead(this, temp, ret);
119 | }
120 | }
121 |
122 | void TcpMediaChannel::OnCloseEvent(talk_base::AsyncSocket* socket, int err) {
123 | assert(socket == tcp_socket_);
124 | if ( is_ready_ == false) {
125 | //SignalChannelClosed(this);
126 | return;
127 | }
128 |
129 | is_ready_ = false;
130 | Close();
131 | SignalChannelClosed(this);
132 | }
133 |
--------------------------------------------------------------------------------
/android/jni/tcpmediachannel.h:
--------------------------------------------------------------------------------
1 | #ifndef _TCPMEDIACHANNEL_H_
2 | #define _TCPMEDIACHANNEL_H_
3 |
4 | #include "mediachannel.h"
5 |
6 | namespace talk_base{
7 | class AsyncSocket;
8 | };
9 |
10 | class TcpMediaChannel: public MediaChannel {
11 | public:
12 | TcpMediaChannel();
13 | virtual ~TcpMediaChannel();
14 |
15 | virtual void Connect(const MediaURL& url);
16 | virtual int PushData(const unsigned char *data, size_t Len);
17 | virtual int Close();
18 |
19 | protected:
20 | void OnConnectEvent(talk_base::AsyncSocket* socket);
21 | void OnCloseEvent(talk_base::AsyncSocket* socket, int err);
22 | void OnReadEvent(talk_base::AsyncSocket* socket);
23 | private:
24 | int doConnect();
25 | void createSocket();
26 |
27 | private:
28 | talk_base::AsyncSocket* tcp_socket_;
29 | MediaURL my_url_;
30 | };
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/android/jni/udpmediachannel.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "talk/base/socketstream.h"
4 | #include "talk/base/asyncsocket.h"
5 | #include "udpmediachannel.h"
6 | #include "helper.h"
7 |
8 | UdpMediaChannel::UdpMediaChannel() {
9 | udp_socket_ = NULL;
10 | }
11 |
12 | UdpMediaChannel::~UdpMediaChannel() {
13 | Close();
14 | }
15 |
16 | int UdpMediaChannel::Close(){
17 | if( udp_socket_) {
18 | udp_socket_->SignalReadEvent.disconnect(this);
19 | udp_socket_->Close();
20 | delete udp_socket_;
21 | udp_socket_ = NULL;
22 | }
23 | return 0;
24 | }
25 |
26 | int UdpMediaChannel::createSocket() {
27 | talk_base::Thread* pth = talk_base::Thread::Current();
28 | talk_base::AsyncSocket* socket =
29 | pth->socketserver()->CreateAsyncSocket(SOCK_DGRAM);
30 | udp_socket_ = socket;
31 | assert(udp_socket_);
32 | udp_socket_->SignalReadEvent.connect(this, &UdpMediaChannel::OnReadEvent);
33 |
34 | int port;
35 | std::string remote_addr;
36 | remote_addr = my_url_.location;
37 | port = atoi( my_url_.resource.c_str());
38 |
39 | LOGD(" Remote Address = %s", remote_addr.c_str());
40 |
41 | talk_base::SocketAddress addr(remote_addr, port);
42 | remote_addr_ = addr;
43 |
44 | return 0;
45 | }
46 |
47 | void UdpMediaChannel::Connect(const MediaURL& url) {
48 | my_url_ = url;
49 | is_ready_ = false;
50 | Close();
51 |
52 | int ret = createSocket();
53 |
54 | if ( ret < 0) {
55 | Close();
56 | SignalChannelOpened(this, false);
57 | return;
58 | }
59 |
60 | is_ready_ = true;
61 | SignalChannelOpened(this, true);
62 | }
63 |
64 | int UdpMediaChannel::PushData(const unsigned char *data, size_t len) {
65 | if ( udp_socket_ == NULL)
66 | return -1;
67 |
68 | if ( udp_socket_->GetState() == talk_base::Socket::CS_CONNECTING)
69 | return 0;
70 |
71 | int result = udp_socket_->SendTo(data, len, remote_addr_);
72 | if (result < 0) {
73 | if (udp_socket_->IsBlocking())
74 | return 0;
75 | return -1;
76 | }
77 | return result;
78 | }
79 |
80 | void UdpMediaChannel::OnReadEvent(talk_base::AsyncSocket* socket) {
81 | assert(socket == udp_socket_);
82 |
83 | unsigned char temp[2048];
84 | int ret = udp_socket_->Recv(temp, sizeof(temp) - 1);
85 | if (ret > 0) {
86 | SignalDataRead(this, temp, ret);
87 | }
88 | }
89 |
90 |
--------------------------------------------------------------------------------
/android/jni/udpmediachannel.h:
--------------------------------------------------------------------------------
1 | #ifndef _UDPMEDIACHANNEL_H_
2 | #define _UDPMEDIACHANNEL_H_
3 |
4 | #include "mediachannel.h"
5 |
6 | namespace talk_base{
7 | class AsyncSocket;
8 | };
9 |
10 | class UdpMediaChannel: public MediaChannel {
11 | public:
12 | UdpMediaChannel();
13 | virtual ~UdpMediaChannel();
14 |
15 | virtual void Connect(const MediaURL& url);
16 | virtual int PushData(const unsigned char *data, size_t Len);
17 | virtual int Close();
18 |
19 | protected:
20 | void OnConnectEvent(talk_base::AsyncSocket* socket);
21 | void OnCloseEvent(talk_base::AsyncSocket* socket, int err);
22 | void OnReadEvent(talk_base::AsyncSocket* socket);
23 | private:
24 | int createSocket();
25 |
26 | private:
27 | talk_base::AsyncSocket* udp_socket_;
28 | talk_base::SocketAddress remote_addr_;
29 | MediaURL my_url_;
30 | };
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/android/jni/x264/common/arm/asm.S:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * asm.S: arm utility macros
3 | *****************************************************************************
4 | * Copyright (C) 2008-2012 x264 project
5 | *
6 | * Authors: Mans Rullgard
7 | * David Conrad
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | *
23 | * This program is also available under a commercial proprietary license.
24 | * For more information, contact us at licensing@x264.com.
25 | *****************************************************************************/
26 |
27 | #include "config.h"
28 |
29 | #ifdef PREFIX
30 | # define EXTERN_ASM _
31 | #else
32 | # define EXTERN_ASM
33 | #endif
34 |
35 | #ifdef __ELF__
36 | # define ELF
37 | #else
38 | # define ELF @
39 | #endif
40 |
41 | .macro require8, val=1
42 | ELF .eabi_attribute 24, \val
43 | .endm
44 |
45 | .macro preserve8, val=1
46 | ELF .eabi_attribute 25, \val
47 | .endm
48 |
49 | .macro function name
50 | .global EXTERN_ASM\name
51 | .align 2
52 | EXTERN_ASM\name:
53 | ELF .hidden \name
54 | ELF .type \name, %function
55 | .func \name
56 | \name:
57 | .endm
58 |
59 | .macro movrel rd, val
60 | #if HAVE_ARMV6T2 && !defined(PIC)
61 | movw \rd, #:lower16:\val
62 | movt \rd, #:upper16:\val
63 | #else
64 | ldr \rd, =\val
65 | #endif
66 | .endm
67 |
68 | .macro movconst rd, val
69 | #if HAVE_ARMV6T2
70 | movw \rd, #:lower16:\val
71 | .if \val >> 16
72 | movt \rd, #:upper16:\val
73 | .endif
74 | #else
75 | ldr \rd, =\val
76 | #endif
77 | .endm
78 |
79 | #define FENC_STRIDE 16
80 | #define FDEC_STRIDE 32
81 |
82 | .macro HORIZ_ADD dest, a, b
83 | .ifnb \b
84 | vadd.u16 \a, \a, \b
85 | .endif
86 | vpaddl.u16 \a, \a
87 | vpaddl.u32 \dest, \a
88 | .endm
89 |
90 | .macro SUMSUB_AB sum, diff, a, b
91 | vadd.s16 \sum, \a, \b
92 | vsub.s16 \diff, \a, \b
93 | .endm
94 |
95 | .macro SUMSUB_ABCD s1, d1, s2, d2, a, b, c, d
96 | SUMSUB_AB \s1, \d1, \a, \b
97 | SUMSUB_AB \s2, \d2, \c, \d
98 | .endm
99 |
100 | .macro ABS2 a b
101 | vabs.s16 \a, \a
102 | vabs.s16 \b, \b
103 | .endm
104 |
105 | // dist = distance in elements (0 for vertical pass, 1/2 for horizontal passes)
106 | // op = sumsub/amax (sum and diff / maximum of absolutes)
107 | // d1/2 = destination registers
108 | // s1/2 = source registers
109 | .macro HADAMARD dist, op, d1, d2, s1, s2
110 | .if \dist == 1
111 | vtrn.16 \s1, \s2
112 | .else
113 | vtrn.32 \s1, \s2
114 | .endif
115 | .ifc \op, sumsub
116 | SUMSUB_AB \d1, \d2, \s1, \s2
117 | .else
118 | vabs.s16 \s1, \s1
119 | vabs.s16 \s2, \s2
120 | vmax.s16 \d1, \s1, \s2
121 | .endif
122 | .endm
123 |
124 | .macro TRANSPOSE8x8 r0 r1 r2 r3 r4 r5 r6 r7
125 | vtrn.32 \r0, \r4
126 | vtrn.32 \r1, \r5
127 | vtrn.32 \r2, \r6
128 | vtrn.32 \r3, \r7
129 | vtrn.16 \r0, \r2
130 | vtrn.16 \r1, \r3
131 | vtrn.16 \r4, \r6
132 | vtrn.16 \r5, \r7
133 | vtrn.8 \r0, \r1
134 | vtrn.8 \r2, \r3
135 | vtrn.8 \r4, \r5
136 | vtrn.8 \r6, \r7
137 | .endm
138 |
139 | .macro TRANSPOSE4x4 r0 r1 r2 r3
140 | vtrn.16 \r0, \r2
141 | vtrn.16 \r1, \r3
142 | vtrn.8 \r0, \r1
143 | vtrn.8 \r2, \r3
144 | .endm
145 |
146 | .macro TRANSPOSE4x4_16 d0 d1 d2 d3
147 | vtrn.32 \d0, \d2
148 | vtrn.32 \d1, \d3
149 | vtrn.16 \d0, \d1
150 | vtrn.16 \d2, \d3
151 | .endm
152 |
--------------------------------------------------------------------------------
/android/jni/x264/common/arm/cpu-a.S:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * cpu-a.S: arm cpu detection
3 | *****************************************************************************
4 | * Copyright (C) 2009-2012 x264 project
5 | *
6 | * Authors: David Conrad
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #include "asm.S"
27 |
28 | .fpu neon
29 | .align
30 |
31 | // done in gas because .fpu neon overrides the refusal to assemble
32 | // instructions the selected -march/-mcpu doesn't support
33 | function x264_cpu_neon_test
34 | vadd.i16 q0, q0, q0
35 | bx lr
36 | .endfunc
37 |
38 | // return: 0 on success
39 | // 1 if counters were already enabled
40 | // 9 if lo-res counters were already enabled
41 | function x264_cpu_enable_armv7_counter
42 | mrc p15, 0, r2, c9, c12, 0 // read PMNC
43 | ands r0, r2, #1
44 | andne r0, r2, #9
45 |
46 | orr r2, r2, #1 // enable counters
47 | bic r2, r2, #8 // full resolution
48 | mcreq p15, 0, r2, c9, c12, 0 // write PMNC
49 | mov r2, #1 << 31 // enable cycle counter
50 | mcr p15, 0, r2, c9, c12, 1 // write CNTENS
51 | bx lr
52 | .endfunc
53 |
54 | function x264_cpu_disable_armv7_counter
55 | mrc p15, 0, r0, c9, c12, 0 // read PMNC
56 | bic r0, r0, #1 // disable counters
57 | mcr p15, 0, r0, c9, c12, 0 // write PMNC
58 | bx lr
59 | .endfunc
60 |
61 |
62 | .macro READ_TIME r
63 | mrc p15, 0, \r, c9, c13, 0
64 | .endm
65 |
66 | // return: 0 if transfers neon -> arm transfers take more than 10 cycles
67 | // nonzero otherwise
68 | function x264_cpu_fast_neon_mrc_test
69 | // check for user access to performance counters
70 | mrc p15, 0, r0, c9, c14, 0
71 | cmp r0, #0
72 | bxeq lr
73 |
74 | push {r4-r6,lr}
75 | bl x264_cpu_enable_armv7_counter
76 | ands r1, r0, #8
77 | mov r3, #0
78 | mov ip, #4
79 | mov r6, #4
80 | moveq r5, #1
81 | movne r5, #64
82 |
83 | average_loop:
84 | mov r4, r5
85 | READ_TIME r1
86 | 1: subs r4, r4, #1
87 | .rept 8
88 | vmov.u32 lr, d0[0]
89 | add lr, lr, lr
90 | .endr
91 | bgt 1b
92 | READ_TIME r2
93 |
94 | subs r6, r6, #1
95 | sub r2, r2, r1
96 | cmpgt r2, #30 << 3 // assume context switch if it took over 30 cycles
97 | addle r3, r3, r2
98 | subles ip, ip, #1
99 | bgt average_loop
100 |
101 | // disable counters if we enabled them
102 | ands r0, r0, #1
103 | bleq x264_cpu_disable_armv7_counter
104 |
105 | lsr r0, r3, #5
106 | cmp r0, #10
107 | movgt r0, #0
108 | pop {r4-r6,pc}
109 | .endfunc
110 |
--------------------------------------------------------------------------------
/android/jni/x264/common/arm/dct.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * dct.h: arm transform and zigzag
3 | *****************************************************************************
4 | * Copyright (C) 2009-2012 x264 project
5 | *
6 | * Authors: David Conrad
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_ARM_DCT_H
27 | #define X264_ARM_DCT_H
28 |
29 | void x264_dct4x4dc_neon( int16_t d[16] );
30 | void x264_idct4x4dc_neon( int16_t d[16] );
31 |
32 | void x264_sub4x4_dct_neon( int16_t dct[16], uint8_t *pix1, uint8_t *pix2 );
33 | void x264_sub8x8_dct_neon( int16_t dct[4][16], uint8_t *pix1, uint8_t *pix2 );
34 | void x264_sub16x16_dct_neon( int16_t dct[16][16], uint8_t *pix1, uint8_t *pix2 );
35 |
36 | void x264_add4x4_idct_neon( uint8_t *p_dst, int16_t dct[16] );
37 | void x264_add8x8_idct_neon( uint8_t *p_dst, int16_t dct[4][16] );
38 | void x264_add16x16_idct_neon( uint8_t *p_dst, int16_t dct[16][16] );
39 |
40 | void x264_add8x8_idct_dc_neon( uint8_t *p_dst, int16_t dct[4] );
41 | void x264_add16x16_idct_dc_neon( uint8_t *p_dst, int16_t dct[16] );
42 | void x264_sub8x8_dct_dc_neon( int16_t dct[4], uint8_t *pix1, uint8_t *pix2 );
43 |
44 | void x264_sub8x8_dct8_neon( int16_t dct[64], uint8_t *pix1, uint8_t *pix2 );
45 | void x264_sub16x16_dct8_neon( int16_t dct[4][64], uint8_t *pix1, uint8_t *pix2 );
46 |
47 | void x264_add8x8_idct8_neon( uint8_t *p_dst, int16_t dct[64] );
48 | void x264_add16x16_idct8_neon( uint8_t *p_dst, int16_t dct[4][64] );
49 |
50 | void x264_zigzag_scan_4x4_frame_neon( int16_t level[16], int16_t dct[16] );
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/android/jni/x264/common/arm/mc.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * mc.h: arm motion compensation
3 | *****************************************************************************
4 | * Copyright (C) 2009-2012 x264 project
5 | *
6 | * Authors: David Conrad
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_ARM_MC_H
27 | #define X264_ARM_MC_H
28 |
29 | void x264_mc_init_arm( int cpu, x264_mc_functions_t *pf );
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/android/jni/x264/common/arm/pixel.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * pixel.h: arm pixel metrics
3 | *****************************************************************************
4 | * Copyright (C) 2009-2012 x264 project
5 | *
6 | * Authors: David Conrad
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_ARM_PIXEL_H
27 | #define X264_ARM_PIXEL_H
28 |
29 | #define DECL_PIXELS( ret, name, suffix, args ) \
30 | ret x264_pixel_##name##_16x16_##suffix args;\
31 | ret x264_pixel_##name##_16x8_##suffix args;\
32 | ret x264_pixel_##name##_8x16_##suffix args;\
33 | ret x264_pixel_##name##_8x8_##suffix args;\
34 | ret x264_pixel_##name##_8x4_##suffix args;\
35 | ret x264_pixel_##name##_4x8_##suffix args;\
36 | ret x264_pixel_##name##_4x4_##suffix args;\
37 |
38 | #define DECL_X1( name, suffix ) \
39 | DECL_PIXELS( int, name, suffix, ( uint8_t *, int, uint8_t *, int ) )
40 |
41 | #define DECL_X4( name, suffix ) \
42 | DECL_PIXELS( void, name##_x3, suffix, ( uint8_t *, uint8_t *, uint8_t *, uint8_t *, intptr_t, int * ) )\
43 | DECL_PIXELS( void, name##_x4, suffix, ( uint8_t *, uint8_t *, uint8_t *, uint8_t *, uint8_t *, intptr_t, int * ) )
44 |
45 | int x264_pixel_sad_4x4_armv6( uint8_t *, intptr_t, uint8_t *, intptr_t );
46 | int x264_pixel_sad_4x8_armv6( uint8_t *, intptr_t, uint8_t *, intptr_t );
47 |
48 | DECL_X1( sad, neon )
49 | DECL_X1( sad_aligned, neon )
50 | DECL_X1( sad_aligned, neon_dual )
51 | DECL_X4( sad, neon )
52 | DECL_X1( satd, neon )
53 | DECL_X1( ssd, neon )
54 |
55 | int x264_pixel_sa8d_8x8_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t );
56 | int x264_pixel_sa8d_16x16_neon( uint8_t *, intptr_t, uint8_t *, intptr_t );
57 |
58 | uint64_t x264_pixel_var_8x8_neon ( uint8_t *, intptr_t );
59 | uint64_t x264_pixel_var_16x16_neon( uint8_t *, intptr_t );
60 | int x264_pixel_var2_8x8_neon( uint8_t *, intptr_t, uint8_t *, intptr_t, int * );
61 |
62 | uint64_t x264_pixel_hadamard_ac_8x8_neon ( uint8_t *, intptr_t );
63 | uint64_t x264_pixel_hadamard_ac_8x16_neon ( uint8_t *, intptr_t );
64 | uint64_t x264_pixel_hadamard_ac_16x8_neon ( uint8_t *, intptr_t );
65 | uint64_t x264_pixel_hadamard_ac_16x16_neon( uint8_t *, intptr_t );
66 |
67 | void x264_pixel_ssim_4x4x2_core_neon( const uint8_t *, intptr_t,
68 | const uint8_t *, intptr_t,
69 | int sums[2][4] );
70 | float x264_pixel_ssim_end4_neon( int sum0[5][4], int sum1[5][4], int width );
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/android/jni/x264/common/arm/predict.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * predict.h: arm intra prediction
3 | *****************************************************************************
4 | * Copyright (C) 2009-2012 x264 project
5 | *
6 | * Authors: David Conrad
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_ARM_PREDICT_H
27 | #define X264_ARM_PREDICT_H
28 |
29 | void x264_predict_4x4_init_arm( int cpu, x264_predict_t pf[12] );
30 | void x264_predict_8x8_init_arm( int cpu, x264_predict8x8_t pf[12], x264_predict_8x8_filter_t *predict_filter );
31 | void x264_predict_8x8c_init_arm( int cpu, x264_predict_t pf[7] );
32 | void x264_predict_16x16_init_arm( int cpu, x264_predict_t pf[7] );
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/android/jni/x264/common/arm/quant.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * quant.h: arm quantization and level-run
3 | *****************************************************************************
4 | * Copyright (C) 2005-2012 x264 project
5 | *
6 | * Authors: David Conrad
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_ARM_QUANT_H
27 | #define X264_ARM_QUANT_H
28 |
29 | int x264_quant_2x2_dc_armv6( int16_t dct[4], int mf, int bias );
30 |
31 | int x264_quant_2x2_dc_neon( int16_t dct[4], int mf, int bias );
32 | int x264_quant_4x4_dc_neon( int16_t dct[16], int mf, int bias );
33 | int x264_quant_4x4_neon( int16_t dct[16], uint16_t mf[16], uint16_t bias[16] );
34 | int x264_quant_8x8_neon( int16_t dct[64], uint16_t mf[64], uint16_t bias[64] );
35 |
36 | void x264_dequant_4x4_dc_neon( int16_t dct[16], int dequant_mf[6][16], int i_qp );
37 | void x264_dequant_4x4_neon( int16_t dct[16], int dequant_mf[6][16], int i_qp );
38 | void x264_dequant_8x8_neon( int16_t dct[64], int dequant_mf[6][64], int i_qp );
39 |
40 | int x264_coeff_last4_arm( int16_t * );
41 | int x264_coeff_last15_neon( int16_t * );
42 | int x264_coeff_last16_neon( int16_t * );
43 | int x264_coeff_last64_neon( int16_t * );
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/android/jni/x264/common/bitstream.c:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * bitstream.c: bitstream writing
3 | *****************************************************************************
4 | * Copyright (C) 2003-2012 x264 project
5 | *
6 | * Authors: Laurent Aimar
7 | * Jason Garrett-Glaser
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | *
23 | * This program is also available under a commercial proprietary license.
24 | * For more information, contact us at licensing@x264.com.
25 | *****************************************************************************/
26 |
27 | #include "common.h"
28 |
29 | static uint8_t *x264_nal_escape_c( uint8_t *dst, uint8_t *src, uint8_t *end )
30 | {
31 | if( src < end ) *dst++ = *src++;
32 | if( src < end ) *dst++ = *src++;
33 | while( src < end )
34 | {
35 | if( src[0] <= 0x03 && !dst[-2] && !dst[-1] )
36 | *dst++ = 0x03;
37 | *dst++ = *src++;
38 | }
39 | return dst;
40 | }
41 |
42 | #if HAVE_MMX
43 | uint8_t *x264_nal_escape_mmx2( uint8_t *dst, uint8_t *src, uint8_t *end );
44 | uint8_t *x264_nal_escape_sse2( uint8_t *dst, uint8_t *src, uint8_t *end );
45 | uint8_t *x264_nal_escape_avx( uint8_t *dst, uint8_t *src, uint8_t *end );
46 | #endif
47 |
48 | /****************************************************************************
49 | * x264_nal_encode:
50 | ****************************************************************************/
51 | void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal )
52 | {
53 | uint8_t *src = nal->p_payload;
54 | uint8_t *end = nal->p_payload + nal->i_payload;
55 | uint8_t *orig_dst = dst;
56 |
57 | if( h->param.b_annexb )
58 | {
59 | if( nal->b_long_startcode )
60 | *dst++ = 0x00;
61 | *dst++ = 0x00;
62 | *dst++ = 0x00;
63 | *dst++ = 0x01;
64 | }
65 | else /* save room for size later */
66 | dst += 4;
67 |
68 | /* nal header */
69 | *dst++ = ( 0x00 << 7 ) | ( nal->i_ref_idc << 5 ) | nal->i_type;
70 |
71 | dst = h->bsf.nal_escape( dst, src, end );
72 | int size = (dst - orig_dst) - 4;
73 |
74 | /* Write the size header for mp4/etc */
75 | if( !h->param.b_annexb )
76 | {
77 | /* Size doesn't include the size of the header we're writing now. */
78 | orig_dst[0] = size>>24;
79 | orig_dst[1] = size>>16;
80 | orig_dst[2] = size>> 8;
81 | orig_dst[3] = size>> 0;
82 | }
83 |
84 | nal->i_payload = size+4;
85 | nal->p_payload = orig_dst;
86 | x264_emms();
87 | }
88 |
89 | void x264_bitstream_init( int cpu, x264_bitstream_function_t *pf )
90 | {
91 | pf->nal_escape = x264_nal_escape_c;
92 | #if HAVE_MMX
93 | if( cpu&X264_CPU_MMX2 )
94 | pf->nal_escape = x264_nal_escape_mmx2;
95 | if( (cpu&X264_CPU_SSE2) && (cpu&X264_CPU_SSE2_IS_FAST) )
96 | pf->nal_escape = x264_nal_escape_sse2;
97 | if( cpu&X264_CPU_AVX )
98 | pf->nal_escape = x264_nal_escape_avx;
99 | #endif
100 | }
101 |
--------------------------------------------------------------------------------
/android/jni/x264/common/cabac.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * cabac.h: arithmetic coder
3 | *****************************************************************************
4 | * Copyright (C) 2003-2012 x264 project
5 | *
6 | * Authors: Loren Merritt
7 | * Laurent Aimar
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | *
23 | * This program is also available under a commercial proprietary license.
24 | * For more information, contact us at licensing@x264.com.
25 | *****************************************************************************/
26 |
27 | #ifndef X264_CABAC_H
28 | #define X264_CABAC_H
29 |
30 | typedef struct
31 | {
32 | /* state */
33 | int i_low;
34 | int i_range;
35 |
36 | /* bit stream */
37 | int i_queue; //stored with an offset of -8 for faster asm
38 | int i_bytes_outstanding;
39 |
40 | uint8_t *p_start;
41 | uint8_t *p;
42 | uint8_t *p_end;
43 |
44 | /* aligned for memcpy_aligned starting here */
45 | ALIGNED_16( int f8_bits_encoded ); // only if using x264_cabac_size_decision()
46 |
47 | /* context */
48 | uint8_t state[1024];
49 |
50 | /* for 16-byte alignment */
51 | uint8_t padding[12];
52 | } x264_cabac_t;
53 |
54 | extern const uint8_t x264_cabac_transition[128][2];
55 | extern const uint16_t x264_cabac_entropy[128];
56 |
57 | /* init the contexts given i_slice_type, the quantif and the model */
58 | void x264_cabac_context_init( x264_t *h, x264_cabac_t *cb, int i_slice_type, int i_qp, int i_model );
59 |
60 | void x264_cabac_encode_init_core( x264_cabac_t *cb );
61 | void x264_cabac_encode_init ( x264_cabac_t *cb, uint8_t *p_data, uint8_t *p_end );
62 | void x264_cabac_encode_decision_c( x264_cabac_t *cb, int i_ctx, int b );
63 | void x264_cabac_encode_decision_asm( x264_cabac_t *cb, int i_ctx, int b );
64 | void x264_cabac_encode_bypass_c( x264_cabac_t *cb, int b );
65 | void x264_cabac_encode_bypass_asm( x264_cabac_t *cb, int b );
66 | void x264_cabac_encode_terminal_c( x264_cabac_t *cb );
67 | void x264_cabac_encode_terminal_asm( x264_cabac_t *cb );
68 | void x264_cabac_encode_ue_bypass( x264_cabac_t *cb, int exp_bits, int val );
69 | void x264_cabac_encode_flush( x264_t *h, x264_cabac_t *cb );
70 |
71 | #if HAVE_MMX
72 | #define x264_cabac_encode_decision x264_cabac_encode_decision_asm
73 | #define x264_cabac_encode_bypass x264_cabac_encode_bypass_asm
74 | #define x264_cabac_encode_terminal x264_cabac_encode_terminal_asm
75 | #else
76 | #define x264_cabac_encode_decision x264_cabac_encode_decision_c
77 | #define x264_cabac_encode_bypass x264_cabac_encode_bypass_c
78 | #define x264_cabac_encode_terminal x264_cabac_encode_terminal_c
79 | #endif
80 | #define x264_cabac_encode_decision_noup x264_cabac_encode_decision
81 |
82 | static ALWAYS_INLINE int x264_cabac_pos( x264_cabac_t *cb )
83 | {
84 | return (cb->p - cb->p_start + cb->i_bytes_outstanding) * 8 + cb->i_queue;
85 | }
86 |
87 | /* internal only. these don't write the bitstream, just calculate bit cost: */
88 |
89 | static ALWAYS_INLINE void x264_cabac_size_decision( x264_cabac_t *cb, long i_ctx, long b )
90 | {
91 | int i_state = cb->state[i_ctx];
92 | cb->state[i_ctx] = x264_cabac_transition[i_state][b];
93 | cb->f8_bits_encoded += x264_cabac_entropy[i_state^b];
94 | }
95 |
96 | static ALWAYS_INLINE int x264_cabac_size_decision2( uint8_t *state, long b )
97 | {
98 | int i_state = *state;
99 | *state = x264_cabac_transition[i_state][b];
100 | return x264_cabac_entropy[i_state^b];
101 | }
102 |
103 | static ALWAYS_INLINE void x264_cabac_size_decision_noup( x264_cabac_t *cb, long i_ctx, long b )
104 | {
105 | int i_state = cb->state[i_ctx];
106 | cb->f8_bits_encoded += x264_cabac_entropy[i_state^b];
107 | }
108 |
109 | static ALWAYS_INLINE int x264_cabac_size_decision_noup2( uint8_t *state, long b )
110 | {
111 | return x264_cabac_entropy[*state^b];
112 | }
113 |
114 | #endif
115 |
--------------------------------------------------------------------------------
/android/jni/x264/common/cpu.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * cpu.h: cpu detection
3 | *****************************************************************************
4 | * Copyright (C) 2004-2012 x264 project
5 | *
6 | * Authors: Loren Merritt
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_CPU_H
27 | #define X264_CPU_H
28 |
29 | uint32_t x264_cpu_detect( void );
30 | int x264_cpu_num_processors( void );
31 | void x264_cpu_emms( void );
32 | void x264_cpu_sfence( void );
33 | #if HAVE_MMX
34 | /* There is no way to forbid the compiler from using float instructions
35 | * before the emms so miscompilation could theoretically occur in the
36 | * unlikely event that the compiler reorders emms and float instructions. */
37 | #if HAVE_X86_INLINE_ASM
38 | /* Clobbering memory makes the compiler less likely to reorder code. */
39 | #define x264_emms() asm volatile( "emms":::"memory","st","st(1)","st(2)", \
40 | "st(3)","st(4)","st(5)","st(6)","st(7)" )
41 | #else
42 | #define x264_emms() x264_cpu_emms()
43 | #endif
44 | #else
45 | #define x264_emms()
46 | #endif
47 | #define x264_sfence x264_cpu_sfence
48 | void x264_cpu_mask_misalign_sse( void );
49 |
50 | /* kluge:
51 | * gcc can't give variables any greater alignment than the stack frame has.
52 | * We need 16 byte alignment for SSE2, so here we make sure that the stack is
53 | * aligned to 16 bytes.
54 | * gcc 4.2 introduced __attribute__((force_align_arg_pointer)) to fix this
55 | * problem, but I don't want to require such a new version.
56 | * This applies only to x86_32, since other architectures that need alignment
57 | * either have ABIs that ensure aligned stack, or don't support it at all. */
58 | #if ARCH_X86 && HAVE_MMX
59 | int x264_stack_align( void (*func)(), ... );
60 | #define x264_stack_align(func,...) x264_stack_align((void (*)())func, __VA_ARGS__)
61 | #else
62 | #define x264_stack_align(func,...) func(__VA_ARGS__)
63 | #endif
64 |
65 | typedef struct
66 | {
67 | const char name[16];
68 | uint32_t flags;
69 | } x264_cpu_name_t;
70 | extern const x264_cpu_name_t x264_cpu_names[];
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/android/jni/x264/common/dct.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * dct.h: transform and zigzag
3 | *****************************************************************************
4 | * Copyright (C) 2004-2012 x264 project
5 | *
6 | * Authors: Loren Merritt
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_DCT_H
27 | #define X264_DCT_H
28 |
29 | extern const uint32_t x264_dct4_weight_tab[16];
30 | extern const uint32_t x264_dct8_weight_tab[64];
31 | extern const uint32_t x264_dct4_weight2_tab[16];
32 | extern const uint32_t x264_dct8_weight2_tab[64];
33 |
34 | typedef struct
35 | {
36 | // pix1 stride = FENC_STRIDE
37 | // pix2 stride = FDEC_STRIDE
38 | // p_dst stride = FDEC_STRIDE
39 | void (*sub4x4_dct) ( dctcoef dct[16], pixel *pix1, pixel *pix2 );
40 | void (*add4x4_idct) ( pixel *p_dst, dctcoef dct[16] );
41 |
42 | void (*sub8x8_dct) ( dctcoef dct[4][16], pixel *pix1, pixel *pix2 );
43 | void (*sub8x8_dct_dc)( dctcoef dct[4], pixel *pix1, pixel *pix2 );
44 | void (*add8x8_idct) ( pixel *p_dst, dctcoef dct[4][16] );
45 | void (*add8x8_idct_dc) ( pixel *p_dst, dctcoef dct[4] );
46 |
47 | void (*sub8x16_dct_dc)( dctcoef dct[8], pixel *pix1, pixel *pix2 );
48 |
49 | void (*sub16x16_dct) ( dctcoef dct[16][16], pixel *pix1, pixel *pix2 );
50 | void (*add16x16_idct)( pixel *p_dst, dctcoef dct[16][16] );
51 | void (*add16x16_idct_dc) ( pixel *p_dst, dctcoef dct[16] );
52 |
53 | void (*sub8x8_dct8) ( dctcoef dct[64], pixel *pix1, pixel *pix2 );
54 | void (*add8x8_idct8) ( pixel *p_dst, dctcoef dct[64] );
55 |
56 | void (*sub16x16_dct8) ( dctcoef dct[4][64], pixel *pix1, pixel *pix2 );
57 | void (*add16x16_idct8)( pixel *p_dst, dctcoef dct[4][64] );
58 |
59 | void (*dct4x4dc) ( dctcoef d[16] );
60 | void (*idct4x4dc)( dctcoef d[16] );
61 |
62 | void (*dct2x4dc)( dctcoef dct[8], dctcoef dct4x4[8][16] );
63 |
64 | } x264_dct_function_t;
65 |
66 | typedef struct
67 | {
68 | void (*scan_8x8)( dctcoef level[64], dctcoef dct[64] );
69 | void (*scan_4x4)( dctcoef level[16], dctcoef dct[16] );
70 | int (*sub_8x8) ( dctcoef level[64], const pixel *p_src, pixel *p_dst );
71 | int (*sub_4x4) ( dctcoef level[16], const pixel *p_src, pixel *p_dst );
72 | int (*sub_4x4ac)( dctcoef level[16], const pixel *p_src, pixel *p_dst, dctcoef *dc );
73 | void (*interleave_8x8_cavlc)( dctcoef *dst, dctcoef *src, uint8_t *nnz );
74 |
75 | } x264_zigzag_function_t;
76 |
77 | void x264_dct_init( int cpu, x264_dct_function_t *dctf );
78 | void x264_dct_init_weights( void );
79 | void x264_zigzag_init( int cpu, x264_zigzag_function_t *pf_progressive, x264_zigzag_function_t *pf_interlaced );
80 |
81 | #endif
82 |
--------------------------------------------------------------------------------
/android/jni/x264/common/display.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * display.h: x11 visualization interface
3 | *****************************************************************************
4 | * Copyright (C) 2005-2012 x264 project
5 | *
6 | * Authors: Tuukka Toivonen
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_DISPLAY_H
27 | #define X264_DISPLAY_H
28 |
29 | void disp_sync(void);
30 | void disp_setcolor(unsigned char *name);
31 | /* Display a region of byte wide memory as a grayscale image.
32 | * num is the window to use for displaying. */
33 | void disp_gray(int num, char *data, int width, int height,
34 | int stride, const unsigned char *title);
35 | void disp_gray_zoom(int num, char *data, int width, int height,
36 | int stride, const unsigned char *title, int zoom);
37 | void disp_point(int num, int x1, int y1);
38 | void disp_line(int num, int x1, int y1, int x2, int y2);
39 | void disp_rect(int num, int x1, int y1, int x2, int y2);
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/android/jni/x264/common/osdep.c:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * osdep.c: platform-specific code
3 | *****************************************************************************
4 | * Copyright (C) 2003-2012 x264 project
5 | *
6 | * Authors: Steven Walters
7 | * Laurent Aimar
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | *
23 | * This program is also available under a commercial proprietary license.
24 | * For more information, contact us at licensing@x264.com.
25 | *****************************************************************************/
26 |
27 | #include "common.h"
28 |
29 | #if SYS_WINDOWS
30 | #include
31 | #include
32 | #else
33 | #include
34 | #endif
35 | #include
36 |
37 | #if PTW32_STATIC_LIB
38 | #define WIN32_LEAN_AND_MEAN
39 | #include
40 | /* this is a global in pthread-win32 to indicate if it has been initialized or not */
41 | extern int ptw32_processInitialized;
42 | #endif
43 |
44 | int64_t x264_mdate( void )
45 | {
46 | #if SYS_WINDOWS
47 | struct timeb tb;
48 | ftime( &tb );
49 | return ((int64_t)tb.time * 1000 + (int64_t)tb.millitm) * 1000;
50 | #else
51 | struct timeval tv_date;
52 | gettimeofday( &tv_date, NULL );
53 | return (int64_t)tv_date.tv_sec * 1000000 + (int64_t)tv_date.tv_usec;
54 | #endif
55 | }
56 |
57 | #if HAVE_WIN32THREAD || PTW32_STATIC_LIB
58 | /* state of the threading library being initialized */
59 | static volatile LONG x264_threading_is_init = 0;
60 |
61 | static void x264_threading_destroy( void )
62 | {
63 | #if PTW32_STATIC_LIB
64 | pthread_win32_thread_detach_np();
65 | pthread_win32_process_detach_np();
66 | #else
67 | x264_win32_threading_destroy();
68 | #endif
69 | }
70 |
71 | int x264_threading_init( void )
72 | {
73 | /* if already init, then do nothing */
74 | if( InterlockedCompareExchange( &x264_threading_is_init, 1, 0 ) )
75 | return 0;
76 | #if PTW32_STATIC_LIB
77 | /* if static pthread-win32 is already initialized, then do nothing */
78 | if( ptw32_processInitialized )
79 | return 0;
80 | if( !pthread_win32_process_attach_np() )
81 | return -1;
82 | #else
83 | if( x264_win32_threading_init() )
84 | return -1;
85 | #endif
86 | /* register cleanup to run at process termination */
87 | atexit( x264_threading_destroy );
88 |
89 | return 0;
90 | }
91 | #endif
92 |
93 | #ifdef __INTEL_COMPILER
94 | /* Agner's patch to Intel's CPU dispatcher from pages 131-132 of
95 | * http://agner.org/optimize/optimizing_cpp.pdf (2011-01-30)
96 | * adapted to x264's cpu schema. */
97 |
98 | // Global variable indicating cpu
99 | int __intel_cpu_indicator = 0;
100 | // CPU dispatcher function
101 | void __intel_cpu_indicator_init( void )
102 | {
103 | unsigned int cpu = x264_cpu_detect();
104 | if( cpu&X264_CPU_AVX )
105 | __intel_cpu_indicator = 0x20000;
106 | else if( cpu&X264_CPU_SSE42 )
107 | __intel_cpu_indicator = 0x8000;
108 | else if( cpu&X264_CPU_SSE4 )
109 | __intel_cpu_indicator = 0x2000;
110 | else if( cpu&X264_CPU_SSSE3 )
111 | __intel_cpu_indicator = 0x1000;
112 | else if( cpu&X264_CPU_SSE3 )
113 | __intel_cpu_indicator = 0x800;
114 | else if( cpu&X264_CPU_SSE2 && !(cpu&X264_CPU_SSE2_IS_SLOW) )
115 | __intel_cpu_indicator = 0x200;
116 | else if( cpu&X264_CPU_SSE )
117 | __intel_cpu_indicator = 0x80;
118 | else if( cpu&X264_CPU_MMX2 )
119 | __intel_cpu_indicator = 8;
120 | else
121 | __intel_cpu_indicator = 1;
122 | }
123 | #endif
124 |
--------------------------------------------------------------------------------
/android/jni/x264/common/ppc/dct.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * dct.h: ppc transform and zigzag
3 | *****************************************************************************
4 | * Copyright (C) 2003-2012 x264 project
5 | *
6 | * Authors: Eric Petit
7 | * Guillaume Poirier
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | *
23 | * This program is also available under a commercial proprietary license.
24 | * For more information, contact us at licensing@x264.com.
25 | *****************************************************************************/
26 |
27 | #ifndef X264_PPC_DCT_H
28 | #define X264_PPC_DCT_H
29 |
30 | void x264_sub4x4_dct_altivec( int16_t dct[16], uint8_t *pix1, uint8_t *pix2 );
31 | void x264_sub8x8_dct_altivec( int16_t dct[4][16], uint8_t *pix1, uint8_t *pix2 );
32 | void x264_sub16x16_dct_altivec( int16_t dct[16][16], uint8_t *pix1, uint8_t *pix2 );
33 |
34 | void x264_add4x4_idct_altivec( uint8_t *p_dst, int16_t dct[16] );
35 | void x264_add8x8_idct_altivec( uint8_t *p_dst, int16_t dct[4][16] );
36 | void x264_add16x16_idct_altivec( uint8_t *p_dst, int16_t dct[16][16] );
37 |
38 | void x264_sub8x8_dct8_altivec( int16_t dct[64], uint8_t *pix1, uint8_t *pix2 );
39 | void x264_sub16x16_dct8_altivec( int16_t dct[4][64], uint8_t *pix1, uint8_t *pix2 );
40 |
41 | void x264_add8x8_idct8_altivec( uint8_t *dst, int16_t dct[64] );
42 | void x264_add16x16_idct8_altivec( uint8_t *dst, int16_t dct[4][64] );
43 |
44 | void x264_zigzag_scan_4x4_frame_altivec( int16_t level[16], int16_t dct[16] );
45 | void x264_zigzag_scan_4x4_field_altivec( int16_t level[16], int16_t dct[16] );
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/android/jni/x264/common/ppc/mc.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * mc.h: ppc motion compensation
3 | *****************************************************************************
4 | * Copyright (C) 2003-2012 x264 project
5 | *
6 | * Authors: Eric Petit
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_PPC_MC_H
27 | #define X264_PPC_MC_H
28 |
29 | void x264_mc_altivec_init( x264_mc_functions_t *pf );
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/android/jni/x264/common/ppc/pixel.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * pixel.h: ppc pixel metrics
3 | *****************************************************************************
4 | * Copyright (C) 2003-2012 x264 project
5 | *
6 | * Authors: Eric Petit
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_PPC_PIXEL_H
27 | #define X264_PPC_PIXEL_H
28 |
29 | void x264_pixel_altivec_init( x264_pixel_function_t *pixf );
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/android/jni/x264/common/ppc/predict.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * predict.h: ppc intra prediction
3 | *****************************************************************************
4 | * Copyright (C) 2007-2012 x264 project
5 | *
6 | * Authors: Guillaume Poirier
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_PPC_PREDICT_H
27 | #define X264_PPC_PREDICT_H
28 |
29 | void x264_predict_16x16_init_altivec ( x264_predict_t pf[7] );
30 | void x264_predict_8x8c_init_altivec( x264_predict_t pf[7] );
31 |
32 | #endif /* X264_PPC_PREDICT_H */
33 |
--------------------------------------------------------------------------------
/android/jni/x264/common/ppc/quant.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * quant.c: ppc quantization
3 | *****************************************************************************
4 | * Copyright (C) 2007-2012 x264 project
5 | *
6 | * Authors: Guillaume Poirier
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_PPC_QUANT_H
27 | #define X264_PPC_QUANT_H
28 |
29 | int x264_quant_4x4_altivec( int16_t dct[16], uint16_t mf[16], uint16_t bias[16] );
30 | int x264_quant_8x8_altivec( int16_t dct[64], uint16_t mf[64], uint16_t bias[64] );
31 |
32 | int x264_quant_4x4_dc_altivec( int16_t dct[16], int mf, int bias );
33 | int x264_quant_2x2_dc_altivec( int16_t dct[4], int mf, int bias );
34 |
35 | void x264_dequant_4x4_altivec( int16_t dct[16], int dequant_mf[6][16], int i_qp );
36 | void x264_dequant_8x8_altivec( int16_t dct[64], int dequant_mf[6][64], int i_qp );
37 | #endif
38 |
--------------------------------------------------------------------------------
/android/jni/x264/common/quant.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * quant.h: quantization and level-run
3 | *****************************************************************************
4 | * Copyright (C) 2005-2012 x264 project
5 | *
6 | * Authors: Loren Merritt
7 | * Jason Garrett-Glaser
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | *
23 | * This program is also available under a commercial proprietary license.
24 | * For more information, contact us at licensing@x264.com.
25 | *****************************************************************************/
26 |
27 | #ifndef X264_QUANT_H
28 | #define X264_QUANT_H
29 |
30 | typedef struct
31 | {
32 | int (*quant_8x8)( dctcoef dct[64], udctcoef mf[64], udctcoef bias[64] );
33 | int (*quant_4x4)( dctcoef dct[16], udctcoef mf[16], udctcoef bias[16] );
34 | int (*quant_4x4_dc)( dctcoef dct[16], int mf, int bias );
35 | int (*quant_2x2_dc)( dctcoef dct[4], int mf, int bias );
36 |
37 | void (*dequant_8x8)( dctcoef dct[64], int dequant_mf[6][64], int i_qp );
38 | void (*dequant_4x4)( dctcoef dct[16], int dequant_mf[6][16], int i_qp );
39 | void (*dequant_4x4_dc)( dctcoef dct[16], int dequant_mf[6][16], int i_qp );
40 |
41 | void (*idct_dequant_2x4_dc)( dctcoef dct[8], dctcoef dct4x4[8][16], int dequant_mf[6][16], int i_qp );
42 | void (*idct_dequant_2x4_dconly)( dctcoef dct[8], int dequant_mf[6][16], int i_qp );
43 |
44 | int (*optimize_chroma_2x2_dc)( dctcoef dct[4], int dequant_mf );
45 | int (*optimize_chroma_2x4_dc)( dctcoef dct[8], int dequant_mf );
46 |
47 | void (*denoise_dct)( dctcoef *dct, uint32_t *sum, udctcoef *offset, int size );
48 |
49 | int (*decimate_score15)( dctcoef *dct );
50 | int (*decimate_score16)( dctcoef *dct );
51 | int (*decimate_score64)( dctcoef *dct );
52 | int (*coeff_last[14])( dctcoef *dct );
53 | int (*coeff_last4)( dctcoef *dct );
54 | int (*coeff_last8)( dctcoef *dct );
55 | int (*coeff_level_run[13])( dctcoef *dct, x264_run_level_t *runlevel );
56 | int (*coeff_level_run4)( dctcoef *dct, x264_run_level_t *runlevel );
57 | int (*coeff_level_run8)( dctcoef *dct, x264_run_level_t *runlevel );
58 |
59 | #define TRELLIS_PARAMS const int *unquant_mf, const uint8_t *zigzag, int lambda2,\
60 | int last_nnz, dctcoef *coefs, dctcoef *quant_coefs, dctcoef *dct,\
61 | uint8_t *cabac_state_sig, uint8_t *cabac_state_last,\
62 | uint64_t level_state0, uint16_t level_state1
63 | int (*trellis_cabac_4x4)( TRELLIS_PARAMS, int b_ac );
64 | int (*trellis_cabac_8x8)( TRELLIS_PARAMS, int b_interlaced );
65 | int (*trellis_cabac_4x4_psy)( TRELLIS_PARAMS, int b_ac, dctcoef *fenc_dct, int psy_trellis );
66 | int (*trellis_cabac_8x8_psy)( TRELLIS_PARAMS, int b_interlaced, dctcoef *fenc_dct, int psy_trellis );
67 | int (*trellis_cabac_dc)( TRELLIS_PARAMS, int num_coefs );
68 | int (*trellis_cabac_chroma_422_dc)( TRELLIS_PARAMS );
69 | } x264_quant_function_t;
70 |
71 | void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf );
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/android/jni/x264/common/rectangle.c:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * rectangle.c: rectangle filling
3 | *****************************************************************************
4 | * Copyright (C) 2010-2012 x264 project
5 | *
6 | * Authors: Jason Garrett-Glaser
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #include "common.h"
27 |
28 | #define CACHE_FUNC(name,size,width,height)\
29 | static void x264_macroblock_cache_##name##_##width##_##height( void *target, uint32_t val )\
30 | {\
31 | x264_macroblock_cache_rect( target, width*size, height, size, val );\
32 | }
33 |
34 | #define CACHE_FUNCS(name,size)\
35 | CACHE_FUNC(name,size,4,4)\
36 | CACHE_FUNC(name,size,2,4)\
37 | CACHE_FUNC(name,size,4,2)\
38 | CACHE_FUNC(name,size,2,2)\
39 | CACHE_FUNC(name,size,2,1)\
40 | CACHE_FUNC(name,size,1,2)\
41 | CACHE_FUNC(name,size,1,1)\
42 | void (*x264_cache_##name##_func_table[10])(void *, uint32_t) =\
43 | {\
44 | x264_macroblock_cache_##name##_1_1,\
45 | x264_macroblock_cache_##name##_2_1,\
46 | x264_macroblock_cache_##name##_1_2,\
47 | x264_macroblock_cache_##name##_2_2,\
48 | NULL,\
49 | x264_macroblock_cache_##name##_4_2,\
50 | NULL,\
51 | x264_macroblock_cache_##name##_2_4,\
52 | NULL,\
53 | x264_macroblock_cache_##name##_4_4\
54 | };\
55 |
56 | CACHE_FUNCS(mv, 4)
57 | CACHE_FUNCS(mvd, 2)
58 | CACHE_FUNCS(ref, 1)
59 |
--------------------------------------------------------------------------------
/android/jni/x264/common/sparc/pixel.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * pixel.h: sparc pixel metrics
3 | *****************************************************************************
4 | * Copyright (C) 2005-2012 x264 project
5 | *
6 | * Authors: Phil Jensen
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_SPARC_PIXEL_H
27 | #define X264_SPARC_PIXEL_H
28 |
29 | int x264_pixel_sad_8x8_vis ( uint8_t *, intptr_t, uint8_t *, intptr_t );
30 | int x264_pixel_sad_8x16_vis ( uint8_t *, intptr_t, uint8_t *, intptr_t );
31 | int x264_pixel_sad_16x8_vis ( uint8_t *, intptr_t, uint8_t *, intptr_t );
32 | int x264_pixel_sad_16x16_vis( uint8_t *, intptr_t, uint8_t *, intptr_t );
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/android/jni/x264/common/threadpool.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * threadpool.h: thread pooling
3 | *****************************************************************************
4 | * Copyright (C) 2010-2012 x264 project
5 | *
6 | * Authors: Steven Walters
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_THREADPOOL_H
27 | #define X264_THREADPOOL_H
28 |
29 | typedef struct x264_threadpool_t x264_threadpool_t;
30 |
31 | #if HAVE_THREAD
32 | int x264_threadpool_init( x264_threadpool_t **p_pool, int threads,
33 | void (*init_func)(void *), void *init_arg );
34 | void x264_threadpool_run( x264_threadpool_t *pool, void *(*func)(void *), void *arg );
35 | void *x264_threadpool_wait( x264_threadpool_t *pool, void *arg );
36 | void x264_threadpool_delete( x264_threadpool_t *pool );
37 | #else
38 | #define x264_threadpool_init(p,t,f,a) -1
39 | #define x264_threadpool_run(p,f,a)
40 | #define x264_threadpool_wait(p,a) NULL
41 | #define x264_threadpool_delete(p)
42 | #endif
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/android/jni/x264/common/visualize.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * visualize.h: visualization
3 | *****************************************************************************
4 | * Copyright (C) 2005-2012 x264 project
5 | *
6 | * Authors: Tuukka Toivonen
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_VISUALIZE_H
27 | #define X264_VISUALIZE_H
28 |
29 | #include "common/common.h"
30 |
31 | int x264_visualize_init( x264_t *h );
32 | void x264_visualize_mb( x264_t *h );
33 | void x264_visualize_show( x264_t *h );
34 | void x264_visualize_close( x264_t *h );
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/android/jni/x264/common/win32thread.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * win32thread.h: windows threading
3 | *****************************************************************************
4 | * Copyright (C) 2010-2012 x264 project
5 | *
6 | * Authors: Steven Walters
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 | *
22 | * This program is also available under a commercial proprietary license.
23 | * For more information, contact us at licensing@x264.com.
24 | *****************************************************************************/
25 |
26 | #ifndef X264_WIN32THREAD_H
27 | #define X264_WIN32THREAD_H
28 |
29 | #define WIN32_LEAN_AND_MEAN
30 | #include
31 | /* the following macro is used within x264 */
32 | #undef ERROR
33 |
34 | typedef struct
35 | {
36 | void *handle;
37 | void *(*func)( void* arg );
38 | void *arg;
39 | void *ret;
40 | } x264_pthread_t;
41 | #define x264_pthread_attr_t int
42 |
43 | /* the conditional variable api for windows 6.0+ uses critical sections and not mutexes */
44 | typedef CRITICAL_SECTION x264_pthread_mutex_t;
45 | #define X264_PTHREAD_MUTEX_INITIALIZER {0}
46 | #define x264_pthread_mutexattr_t int
47 |
48 | /* This is the CONDITIONAL_VARIABLE typedef for using Window's native conditional variables on kernels 6.0+.
49 | * MinGW does not currently have this typedef. */
50 | typedef struct
51 | {
52 | void *ptr;
53 | } x264_pthread_cond_t;
54 | #define x264_pthread_condattr_t int
55 |
56 | int x264_pthread_create( x264_pthread_t *thread, const x264_pthread_attr_t *attr,
57 | void *(*start_routine)( void* ), void *arg );
58 | int x264_pthread_join( x264_pthread_t thread, void **value_ptr );
59 |
60 | int x264_pthread_mutex_init( x264_pthread_mutex_t *mutex, const x264_pthread_mutexattr_t *attr );
61 | int x264_pthread_mutex_destroy( x264_pthread_mutex_t *mutex );
62 | int x264_pthread_mutex_lock( x264_pthread_mutex_t *mutex );
63 | int x264_pthread_mutex_unlock( x264_pthread_mutex_t *mutex );
64 |
65 | int x264_pthread_cond_init( x264_pthread_cond_t *cond, const x264_pthread_condattr_t *attr );
66 | int x264_pthread_cond_destroy( x264_pthread_cond_t *cond );
67 | int x264_pthread_cond_broadcast( x264_pthread_cond_t *cond );
68 | int x264_pthread_cond_wait( x264_pthread_cond_t *cond, x264_pthread_mutex_t *mutex );
69 | int x264_pthread_cond_signal( x264_pthread_cond_t *cond );
70 |
71 | #define x264_pthread_attr_init(a) 0
72 | #define x264_pthread_attr_destroy(a) 0
73 |
74 | int x264_win32_threading_init( void );
75 | void x264_win32_threading_destroy( void );
76 |
77 | int x264_pthread_num_processors_np( void );
78 |
79 | #endif
80 |
--------------------------------------------------------------------------------
/android/jni/x264/common/x86/bitstream-a.asm:
--------------------------------------------------------------------------------
1 | ;*****************************************************************************
2 | ;* bitstream-a.asm: x86 bitstream functions
3 | ;*****************************************************************************
4 | ;* Copyright (C) 2010-2012 x264 project
5 | ;*
6 | ;* Authors: Jason Garrett-Glaser
7 | ;* Henrik Gramner
8 | ;*
9 | ;* This program is free software; you can redistribute it and/or modify
10 | ;* it under the terms of the GNU General Public License as published by
11 | ;* the Free Software Foundation; either version 2 of the License, or
12 | ;* (at your option) any later version.
13 | ;*
14 | ;* This program is distributed in the hope that it will be useful,
15 | ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ;* GNU General Public License for more details.
18 | ;*
19 | ;* You should have received a copy of the GNU General Public License
20 | ;* along with this program; if not, write to the Free Software
21 | ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | ;*
23 | ;* This program is also available under a commercial proprietary license.
24 | ;* For more information, contact us at licensing@x264.com.
25 | ;*****************************************************************************
26 |
27 | %include "x86inc.asm"
28 | %include "x86util.asm"
29 |
30 | SECTION .text
31 |
32 | ;-----------------------------------------------------------------------------
33 | ; uint8_t *x264_nal_escape( uint8_t *dst, uint8_t *src, uint8_t *end )
34 | ;-----------------------------------------------------------------------------
35 |
36 | %macro NAL_LOOP 2
37 | %1_escape:
38 | ; Detect false positive to avoid unneccessary escape loop
39 | xor r3d, r3d
40 | cmp byte [r0+r1-1], 0
41 | setnz r3b
42 | xor r3d, r4d
43 | jnz .escape
44 | jmp %1_continue
45 | ALIGN 16
46 | %1:
47 | pcmpeqb m3, m1, m4
48 | pcmpeqb m2, m0, m4
49 | pmovmskb r3d, m3
50 | %2 [r0+r1], m0
51 | pmovmskb r4d, m2
52 | shl r3d, mmsize
53 | mova m0, [r1+r2+2*mmsize]
54 | or r4d, r3d
55 | %2 [r0+r1+mmsize], m1
56 | lea r3d, [r4+r4+1]
57 | mova m1, [r1+r2+3*mmsize]
58 | and r4d, r3d
59 | jnz %1_escape
60 | %1_continue:
61 | add r1, 2*mmsize
62 | jl %1
63 | %endmacro
64 |
65 | %macro NAL_ESCAPE 0
66 |
67 | cglobal nal_escape, 3,5
68 | mov r3w, [r1]
69 | sub r1, r2 ; r1 = offset of current src pointer from end of src
70 | pxor m4, m4
71 | sub r0, r1 ; r0 = projected end of dst, assuming no more escapes
72 | mov [r0+r1], r3w
73 | add r1, 2
74 | jge .ret
75 |
76 | ; Start off by jumping into the escape loop in
77 | ; case there's an escape at the start.
78 | ; And do a few more in scalar until src is aligned again.
79 | jmp .first_escape
80 |
81 | NAL_LOOP .loop_aligned, mova
82 | %if mmsize==16
83 | jmp .ret
84 | NAL_LOOP .loop_unaligned, movu
85 | %endif
86 | .ret:
87 | movifnidn rax, r0
88 | RET
89 |
90 | ALIGN 16
91 | .escape:
92 | ; Skip bytes that are known to be valid
93 | and r4d, r3d
94 | tzcnt r3d, r4d
95 | add r1, r3
96 | .escape_loop:
97 | inc r1
98 | jge .ret
99 | .first_escape:
100 | movzx r3d, byte [r1+r2]
101 | lea r4, [r1+r2]
102 | cmp r3d, 3
103 | jna .escape_check
104 | .no_escape:
105 | mov [r0+r1], r3b
106 | test r4d, mmsize-1 ; Do SIMD when src is aligned
107 | jnz .escape_loop
108 | mova m0, [r4]
109 | mova m1, [r4+mmsize]
110 | %if mmsize==16
111 | lea r4d, [r0+r1]
112 | test r4d, mmsize-1
113 | jnz .loop_unaligned
114 | %endif
115 | jmp .loop_aligned
116 |
117 | ALIGN 16
118 | .escape_check:
119 | cmp word [r0+r1-2], 0
120 | jnz .no_escape
121 | mov byte [r0+r1], 3
122 | inc r0
123 | jmp .no_escape
124 | %endmacro
125 |
126 | INIT_MMX mmx2
127 | NAL_ESCAPE
128 | INIT_XMM sse2
129 | NAL_ESCAPE
130 | INIT_XMM avx
131 | NAL_ESCAPE
132 |
--------------------------------------------------------------------------------
/android/jni/x264/common/x86/const-a.asm:
--------------------------------------------------------------------------------
1 | ;*****************************************************************************
2 | ;* const-a.asm: x86 global constants
3 | ;*****************************************************************************
4 | ;* Copyright (C) 2010-2012 x264 project
5 | ;*
6 | ;* Authors: Loren Merritt
7 | ;* Jason Garrett-Glaser
8 | ;*
9 | ;* This program is free software; you can redistribute it and/or modify
10 | ;* it under the terms of the GNU General Public License as published by
11 | ;* the Free Software Foundation; either version 2 of the License, or
12 | ;* (at your option) any later version.
13 | ;*
14 | ;* This program is distributed in the hope that it will be useful,
15 | ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ;* GNU General Public License for more details.
18 | ;*
19 | ;* You should have received a copy of the GNU General Public License
20 | ;* along with this program; if not, write to the Free Software
21 | ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | ;*
23 | ;* This program is also available under a commercial proprietary license.
24 | ;* For more information, contact us at licensing@x264.com.
25 | ;*****************************************************************************
26 |
27 | %include "x86inc.asm"
28 |
29 | SECTION_RODATA
30 |
31 | const pb_01, times 8 db 0,1
32 | const pb_0, times 16 db 0
33 | const pb_a1, times 16 db 0xa1
34 | const pb_1, times 16 db 1
35 | const pb_3, times 16 db 3
36 | const hsub_mul, times 8 db 1, -1
37 | const pb_shuf8x8c, db 0,0,0,0,2,2,2,2,4,4,4,4,6,6,6,6
38 |
39 | const pw_1, times 8 dw 1
40 | const pw_2, times 8 dw 2
41 | const pw_m2, times 8 dw -2
42 | const pw_4, times 8 dw 4
43 | const pw_8, times 8 dw 8
44 | const pw_16, times 8 dw 16
45 | const pw_32, times 8 dw 32
46 | const pw_64, times 8 dw 64
47 | const pw_32_0, times 4 dw 32,
48 | times 4 dw 0
49 | const pw_8000, times 8 dw 0x8000
50 | const pw_3fff, times 8 dw 0x3fff
51 | const pw_pixel_max,times 8 dw ((1 << BIT_DEPTH)-1)
52 | const pw_ppppmmmm, dw 1,1,1,1,-1,-1,-1,-1
53 | const pw_ppmmppmm, dw 1,1,-1,-1,1,1,-1,-1
54 | const pw_pmpmpmpm, dw 1,-1,1,-1,1,-1,1,-1
55 | const pw_pmmpzzzz, dw 1,-1,-1,1,0,0,0,0
56 |
57 | const pd_1, times 4 dd 1
58 | const pd_32, times 4 dd 32
59 | const pd_1024, times 4 dd 1024
60 | const pd_ffff, times 4 dd 0xffff
61 | const pw_00ff, times 8 dw 0x00ff
62 | const pw_ff00, times 8 dw 0xff00
63 |
64 | const sw_64, dd 64
65 |
--------------------------------------------------------------------------------
/android/jni/x264/common/x86/cpu-a.asm:
--------------------------------------------------------------------------------
1 | ;*****************************************************************************
2 | ;* cpu-a.asm: x86 cpu utilities
3 | ;*****************************************************************************
4 | ;* Copyright (C) 2003-2012 x264 project
5 | ;*
6 | ;* Authors: Laurent Aimar
7 | ;* Loren Merritt
8 | ;* Jason Garrett-Glaser
9 | ;*
10 | ;* This program is free software; you can redistribute it and/or modify
11 | ;* it under the terms of the GNU General Public License as published by
12 | ;* the Free Software Foundation; either version 2 of the License, or
13 | ;* (at your option) any later version.
14 | ;*
15 | ;* This program is distributed in the hope that it will be useful,
16 | ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | ;* GNU General Public License for more details.
19 | ;*
20 | ;* You should have received a copy of the GNU General Public License
21 | ;* along with this program; if not, write to the Free Software
22 | ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
23 | ;*
24 | ;* This program is also available under a commercial proprietary license.
25 | ;* For more information, contact us at licensing@x264.com.
26 | ;*****************************************************************************
27 |
28 | %include "x86inc.asm"
29 |
30 | SECTION .text
31 |
32 | ;-----------------------------------------------------------------------------
33 | ; void cpu_cpuid( int op, int *eax, int *ebx, int *ecx, int *edx )
34 | ;-----------------------------------------------------------------------------
35 | cglobal cpu_cpuid, 5,7
36 | push rbx
37 | push r4
38 | push r3
39 | push r2
40 | push r1
41 | mov eax, r0d
42 | xor ecx, ecx
43 | cpuid
44 | pop r4
45 | mov [r4], eax
46 | pop r4
47 | mov [r4], ebx
48 | pop r4
49 | mov [r4], ecx
50 | pop r4
51 | mov [r4], edx
52 | pop rbx
53 | RET
54 |
55 | ;-----------------------------------------------------------------------------
56 | ; void cpu_xgetbv( int op, int *eax, int *edx )
57 | ;-----------------------------------------------------------------------------
58 | cglobal cpu_xgetbv, 3,7
59 | push r2
60 | push r1
61 | mov ecx, r0d
62 | xgetbv
63 | pop r4
64 | mov [r4], eax
65 | pop r4
66 | mov [r4], edx
67 | RET
68 |
69 | %if ARCH_X86_64 == 0
70 |
71 | ;-----------------------------------------------------------------------------
72 | ; int cpu_cpuid_test( void )
73 | ; return 0 if unsupported
74 | ;-----------------------------------------------------------------------------
75 | cglobal cpu_cpuid_test
76 | pushfd
77 | push ebx
78 | push ebp
79 | push esi
80 | push edi
81 | pushfd
82 | pop eax
83 | mov ebx, eax
84 | xor eax, 0x200000
85 | push eax
86 | popfd
87 | pushfd
88 | pop eax
89 | xor eax, ebx
90 | pop edi
91 | pop esi
92 | pop ebp
93 | pop ebx
94 | popfd
95 | ret
96 |
97 | ;-----------------------------------------------------------------------------
98 | ; void stack_align( void (*func)(void*), void *arg );
99 | ;-----------------------------------------------------------------------------
100 | cglobal stack_align
101 | push ebp
102 | mov ebp, esp
103 | sub esp, 12
104 | and esp, ~15
105 | mov ecx, [ebp+8]
106 | mov edx, [ebp+12]
107 | mov [esp], edx
108 | mov edx, [ebp+16]
109 | mov [esp+4], edx
110 | mov edx, [ebp+20]
111 | mov [esp+8], edx
112 | call ecx
113 | leave
114 | ret
115 |
116 | %endif
117 |
118 | ;-----------------------------------------------------------------------------
119 | ; void cpu_emms( void )
120 | ;-----------------------------------------------------------------------------
121 | cglobal cpu_emms
122 | emms
123 | ret
124 |
125 | ;-----------------------------------------------------------------------------
126 | ; void cpu_sfence( void )
127 | ;-----------------------------------------------------------------------------
128 | cglobal cpu_sfence
129 | sfence
130 | ret
131 |
132 | ;-----------------------------------------------------------------------------
133 | ; void cpu_mask_misalign_sse( void )
134 | ;-----------------------------------------------------------------------------
135 | cglobal cpu_mask_misalign_sse
136 | sub rsp, 4
137 | stmxcsr [rsp]
138 | or dword [rsp], 1<<17
139 | ldmxcsr [rsp]
140 | add rsp, 4
141 | ret
142 |
--------------------------------------------------------------------------------
/android/jni/x264/common/x86/mc.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * mc.h: x86 motion compensation
3 | *****************************************************************************
4 | * Copyright (C) 2003-2012 x264 project
5 | *
6 | * Authors: Loren Merritt
7 | * Laurent Aimar
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | *
23 | * This program is also available under a commercial proprietary license.
24 | * For more information, contact us at licensing@x264.com.
25 | *****************************************************************************/
26 |
27 | #ifndef X264_I386_MC_H
28 | #define X264_I386_MC_H
29 |
30 | void x264_mc_init_mmx( int cpu, x264_mc_functions_t *pf );
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/android/jni/x264/config.h:
--------------------------------------------------------------------------------
1 | #ifdef NDK_ARM
2 | #define ARCH_ARM 1
3 | #endif
4 |
5 | #ifdef NDK_X86
6 | #define ARCH_X86 1
7 | #endif
8 |
9 | #define SYS_LINUX 1
10 | #define HAVE_POSIXTHREAD 0
11 | #define HAVE_THREAD 0
12 | #define HAVE_LOG2F 0
13 | #define HAVE_VECTOREXT 1
14 | #define fseek fseeko
15 | #define ftell ftello
16 | #define HAVE_GPL 1
17 | #define HAVE_INTERLACED 1
18 | #define HAVE_MALLOC_H 1
19 | #define HAVE_ALTIVEC 0
20 | #define HAVE_ALTIVEC_H 0
21 | #define HAVE_MMX 0
22 | #define HAVE_ARMV6 0
23 | #define HAVE_ARMV6T2 0
24 | #define HAVE_NEON 0
25 | #define HAVE_BEOSTHREAD 0
26 | #define HAVE_WIN32THREAD 0
27 | #define HAVE_VISUALIZE 0
28 | #define HAVE_SWSCALE 0
29 | #define HAVE_LAVF 0
30 | #define HAVE_FFMS 0
31 | #define HAVE_GPAC 0
32 | #define HAVE_GF_MALLOC 0
33 | #define HAVE_AVS 0
34 | #define HAVE_CPU_COUNT 0
35 |
--------------------------------------------------------------------------------
/android/jni/x264/encoder/analyse.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * analyse.h: macroblock analysis
3 | *****************************************************************************
4 | * Copyright (C) 2003-2012 x264 project
5 | *
6 | * Authors: Laurent Aimar
7 | * Loren Merritt
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | *
23 | * This program is also available under a commercial proprietary license.
24 | * For more information, contact us at licensing@x264.com.
25 | *****************************************************************************/
26 |
27 | #ifndef X264_ANALYSE_H
28 | #define X264_ANALYSE_H
29 |
30 | float *x264_analyse_prepare_costs( x264_t *h );
31 | int x264_analyse_init_costs( x264_t *h, float *logs, int qp );
32 | void x264_analyse_free_costs( x264_t *h );
33 | void x264_analyse_weight_frame( x264_t *h, int end );
34 | void x264_macroblock_analyse( x264_t *h );
35 | void x264_slicetype_decide( x264_t *h );
36 |
37 | void x264_slicetype_analyse( x264_t *h, int keyframe );
38 |
39 | int x264_weighted_reference_duplicate( x264_t *h, int i_ref, const x264_weight_t *w );
40 |
41 | int x264_lookahead_init( x264_t *h, int i_slicetype_length );
42 | int x264_lookahead_is_empty( x264_t *h );
43 | void x264_lookahead_put_frame( x264_t *h, x264_frame_t *frame );
44 | void x264_lookahead_get_frames( x264_t *h );
45 | void x264_lookahead_delete( x264_t *h );
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/android/jni/x264/encoder/me.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * me.h: motion estimation
3 | *****************************************************************************
4 | * Copyright (C) 2003-2012 x264 project
5 | *
6 | * Authors: Loren Merritt
7 | * Laurent Aimar
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | *
23 | * This program is also available under a commercial proprietary license.
24 | * For more information, contact us at licensing@x264.com.
25 | *****************************************************************************/
26 |
27 | #ifndef X264_ME_H
28 | #define X264_ME_H
29 |
30 | #define COST_MAX (1<<28)
31 | #define COST_MAX64 (1ULL<<60)
32 |
33 | typedef struct
34 | {
35 | /* aligning the first member is a gcc hack to force the struct to be
36 | * 16 byte aligned, as well as force sizeof(struct) to be a multiple of 16 */
37 | /* input */
38 | ALIGNED_16( int i_pixel ); /* PIXEL_WxH */
39 | uint16_t *p_cost_mv; /* lambda * nbits for each possible mv */
40 | int i_ref_cost;
41 | int i_ref;
42 | const x264_weight_t *weight;
43 |
44 | pixel *p_fref[12];
45 | pixel *p_fref_w;
46 | pixel *p_fenc[3];
47 | uint16_t *integral;
48 | int i_stride[3];
49 |
50 | ALIGNED_4( int16_t mvp[2] );
51 |
52 | /* output */
53 | int cost_mv; /* lambda * nbits for the chosen mv */
54 | int cost; /* satd + lambda * nbits */
55 | ALIGNED_4( int16_t mv[2] );
56 | } ALIGNED_16( x264_me_t );
57 |
58 | typedef struct
59 | {
60 | int sad;
61 | int16_t mv[2];
62 | } mvsad_t;
63 |
64 | void x264_me_search_ref( x264_t *h, x264_me_t *m, int16_t (*mvc)[2], int i_mvc, int *p_fullpel_thresh );
65 | #define x264_me_search( h, m, mvc, i_mvc )\
66 | x264_me_search_ref( h, m, mvc, i_mvc, NULL )
67 |
68 | void x264_me_refine_qpel( x264_t *h, x264_me_t *m );
69 | void x264_me_refine_qpel_refdupe( x264_t *h, x264_me_t *m, int *p_halfpel_thresh );
70 | void x264_me_refine_qpel_rd( x264_t *h, x264_me_t *m, int i_lambda2, int i4, int i_list );
71 | void x264_me_refine_bidir_rd( x264_t *h, x264_me_t *m0, x264_me_t *m1, int i_weight, int i8, int i_lambda2 );
72 | void x264_me_refine_bidir_satd( x264_t *h, x264_me_t *m0, x264_me_t *m1, int i_weight );
73 | uint64_t x264_rd_cost_part( x264_t *h, int i_lambda2, int i8, int i_pixel );
74 |
75 | extern uint16_t *x264_cost_mv_fpel[QP_MAX+1][4];
76 |
77 | #define COPY1_IF_LT(x,y)\
78 | if((y)<(x))\
79 | (x)=(y);
80 |
81 | #define COPY2_IF_LT(x,y,a,b)\
82 | if((y)<(x))\
83 | {\
84 | (x)=(y);\
85 | (a)=(b);\
86 | }
87 |
88 | #define COPY3_IF_LT(x,y,a,b,c,d)\
89 | if((y)<(x))\
90 | {\
91 | (x)=(y);\
92 | (a)=(b);\
93 | (c)=(d);\
94 | }
95 |
96 | #define COPY4_IF_LT(x,y,a,b,c,d,e,f)\
97 | if((y)<(x))\
98 | {\
99 | (x)=(y);\
100 | (a)=(b);\
101 | (c)=(d);\
102 | (e)=(f);\
103 | }
104 |
105 | #define COPY2_IF_GT(x,y,a,b)\
106 | if((y)>(x))\
107 | {\
108 | (x)=(y);\
109 | (a)=(b);\
110 | }
111 |
112 | #endif
113 |
--------------------------------------------------------------------------------
/android/jni/x264/encoder/ratecontrol.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/_ref_AndroidRTC/7998dddd7f0c1a48349b240bf1f2732c059bfe2d/android/jni/x264/encoder/ratecontrol.c
--------------------------------------------------------------------------------
/android/jni/x264/encoder/ratecontrol.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * ratecontrol.h: ratecontrol
3 | *****************************************************************************
4 | * Copyright (C) 2003-2012 x264 project
5 | *
6 | * Authors: Loren Merritt
7 | * Laurent Aimar
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | *
23 | * This program is also available under a commercial proprietary license.
24 | * For more information, contact us at licensing@x264.com.
25 | *****************************************************************************/
26 |
27 | #ifndef X264_RATECONTROL_H
28 | #define X264_RATECONTROL_H
29 |
30 | /* Completely arbitrary. Ratecontrol lowers relative quality at higher framerates
31 | * and the reverse at lower framerates; this serves as the center of the curve.
32 | * Halve all the values for frame-packed 3D to compensate for the "doubled"
33 | * framerate. */
34 | #define BASE_FRAME_DURATION (0.04f / ((h->param.i_frame_packing == 5)+1))
35 |
36 | /* Arbitrary limitations as a sanity check. */
37 | #define MAX_FRAME_DURATION (1.00f / ((h->param.i_frame_packing == 5)+1))
38 | #define MIN_FRAME_DURATION (0.01f / ((h->param.i_frame_packing == 5)+1))
39 |
40 | #define CLIP_DURATION(f) x264_clip3f(f,MIN_FRAME_DURATION,MAX_FRAME_DURATION)
41 |
42 | int x264_ratecontrol_new ( x264_t * );
43 | void x264_ratecontrol_delete( x264_t * );
44 |
45 | void x264_ratecontrol_init_reconfigurable( x264_t *h, int b_init );
46 |
47 | void x264_adaptive_quant_frame( x264_t *h, x264_frame_t *frame, float *quant_offsets );
48 | int x264_macroblock_tree_read( x264_t *h, x264_frame_t *frame, float *quant_offsets );
49 | int x264_reference_build_list_optimal( x264_t *h );
50 | void x264_thread_sync_ratecontrol( x264_t *cur, x264_t *prev, x264_t *next );
51 | void x264_ratecontrol_start( x264_t *, int i_force_qp, int overhead );
52 | int x264_ratecontrol_slice_type( x264_t *, int i_frame );
53 | void x264_ratecontrol_set_weights( x264_t *h, x264_frame_t *frm );
54 | int x264_ratecontrol_mb( x264_t *, int bits );
55 | int x264_ratecontrol_qp( x264_t * );
56 | int x264_ratecontrol_mb_qp( x264_t *h );
57 | int x264_ratecontrol_end( x264_t *, int bits, int *filler );
58 | void x264_ratecontrol_summary( x264_t * );
59 | void x264_ratecontrol_set_estimated_size( x264_t *, int bits );
60 | int x264_ratecontrol_get_estimated_size( x264_t const *);
61 | int x264_rc_analyse_slice( x264_t *h );
62 | int x264_weighted_reference_duplicate( x264_t *h, int i_ref, const x264_weight_t *w );
63 | void x264_threads_distribute_ratecontrol( x264_t *h );
64 | void x264_threads_merge_ratecontrol( x264_t *h );
65 | void x264_hrd_fullness( x264_t *h );
66 | #endif
67 |
68 |
--------------------------------------------------------------------------------
/android/jni/x264/encoder/set.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * set.h: header writing
3 | *****************************************************************************
4 | * Copyright (C) 2003-2012 x264 project
5 | *
6 | * Authors: Laurent Aimar
7 | * Loren Merritt
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 | *
23 | * This program is also available under a commercial proprietary license.
24 | * For more information, contact us at licensing@x264.com.
25 | *****************************************************************************/
26 |
27 | #ifndef X264_ENCODER_SET_H
28 | #define X264_ENCODER_SET_H
29 |
30 | void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param );
31 | void x264_sps_write( bs_t *s, x264_sps_t *sps );
32 | void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *sps );
33 | void x264_pps_write( bs_t *s, x264_sps_t *sps, x264_pps_t *pps );
34 | void x264_sei_recovery_point_write( x264_t *h, bs_t *s, int recovery_frame_cnt );
35 | int x264_sei_version_write( x264_t *h, bs_t *s );
36 | int x264_validate_levels( x264_t *h, int verbose );
37 | void x264_sei_buffering_period_write( x264_t *h, bs_t *s );
38 | void x264_sei_pic_timing_write( x264_t *h, bs_t *s );
39 | void x264_sei_dec_ref_pic_marking_write( x264_t *h, bs_t *s );
40 | void x264_sei_frame_packing_write( x264_t *h, bs_t *s );
41 | void x264_sei_write( bs_t *s, uint8_t *payload, int payload_size, int payload_type );
42 | void x264_filler_write( x264_t *h, bs_t *s, int filler );
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/android/jni/x264/x264_config.h:
--------------------------------------------------------------------------------
1 | #define X264_BIT_DEPTH 8
2 | #define X264_GPL 1
3 | #define X264_INTERLACED 1
4 | #define X264_CHROMA_FORMAT 0
5 | #define X264_REV 0
6 | #define X264_REV_DIFF 3
7 | #define X264_VERSION " r0+3M 8db9396"
8 | #define X264_POINTVER "0.129.0+3M 8db9396"
9 |
--------------------------------------------------------------------------------
/android/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-8
15 |
--------------------------------------------------------------------------------
/android/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Teaonly/_ref_AndroidRTC/7998dddd7f0c1a48349b240bf1f2732c059bfe2d/android/res/drawable/icon.png
--------------------------------------------------------------------------------
/android/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
21 |
22 |
28 |
29 |
46 |
47 |
53 |
61 |
69 |
70 |
71 |
77 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/android/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Android RTC
4 |
5 | Start
6 | Stop
7 |
8 |
9 |
--------------------------------------------------------------------------------
/android/src/teaonly/rtc/OverlayView.java:
--------------------------------------------------------------------------------
1 | package teaonly.rtc;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.PorterDuff;
10 | import android.graphics.PorterDuffXfermode;
11 | import android.graphics.Rect;
12 | import android.graphics.RectF;
13 | import android.util.AttributeSet;
14 | import android.util.Log;
15 | import android.view.View;
16 |
17 | public class OverlayView extends View {
18 | public static interface UpdateDoneCallback {
19 | public void onUpdateDone();
20 | }
21 |
22 | private UpdateDoneCallback updateDoneCb = null;
23 | private Bitmap targetBMP = null;
24 | private Rect targetRect = null;
25 |
26 |
27 | public OverlayView(Context c, AttributeSet attr) {
28 | super(c, attr);
29 | }
30 |
31 | public void DrawResult(Bitmap bmp) {
32 | if ( targetRect == null)
33 | targetRect = new Rect(0, 0, bmp.getWidth(), bmp.getHeight());
34 | targetBMP = bmp;
35 | postInvalidate();
36 | }
37 |
38 | public void setUpdateDoneCallback(UpdateDoneCallback cb) {
39 | updateDoneCb = cb;
40 | }
41 |
42 | @Override
43 | protected void onDraw(Canvas canvas) {
44 | if ( targetBMP != null ) {
45 |
46 | canvas.drawBitmap(targetBMP, null, targetRect, null);
47 |
48 | if ( updateDoneCb != null)
49 | updateDoneCb.onUpdateDone();
50 | }
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/android/src/teaonly/task/GenericTask.java:
--------------------------------------------------------------------------------
1 | package teaonly.task;
2 |
3 | import java.util.Observable;
4 | import java.util.Observer;
5 |
6 | import android.os.AsyncTask;
7 | import android.util.Log;
8 |
9 | public abstract class GenericTask extends
10 | AsyncTask {
11 | private static final String TAG = "TaskManager";
12 |
13 | private TaskListener mListener = null;
14 | private boolean isCancelable = true;
15 |
16 | abstract protected TaskResult _doInBackground(TaskParams... params);
17 |
18 | public void setListener(TaskListener taskListener) {
19 | mListener = taskListener;
20 | }
21 |
22 | public TaskListener getListener() {
23 | return mListener;
24 | }
25 |
26 | public void doPublishProgress(Object... values) {
27 | super.publishProgress(values);
28 | }
29 |
30 | @Override
31 | protected void onCancelled() {
32 | super.onCancelled();
33 |
34 | if (mListener != null) {
35 | mListener.onCancelled(this);
36 | }
37 | Log.i(TAG, mListener.getName() + " has been Cancelled.");
38 | }
39 |
40 | @Override
41 | protected void onPostExecute(TaskResult result) {
42 | super.onPostExecute(result);
43 |
44 | if (mListener != null) {
45 | mListener.onPostExecute(this, result);
46 | }
47 | }
48 |
49 | @Override
50 | protected void onPreExecute() {
51 | super.onPreExecute();
52 |
53 | if (mListener != null) {
54 | mListener.onPreExecute(this);
55 | }
56 | }
57 |
58 | @Override
59 | protected void onProgressUpdate(Object... values) {
60 | super.onProgressUpdate(values);
61 |
62 | if (mListener != null) {
63 | if (values != null && values.length > 0) {
64 | mListener.onProgressUpdate(this, values[0]);
65 | }
66 | }
67 | }
68 |
69 | @Override
70 | protected TaskResult doInBackground(TaskParams... params) {
71 | return _doInBackground(params);
72 | }
73 |
74 | public void setCancelable(boolean flag) {
75 | isCancelable = flag;
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/android/src/teaonly/task/TaskAdapter.java:
--------------------------------------------------------------------------------
1 | package teaonly.task;
2 |
3 | public abstract class TaskAdapter implements TaskListener {
4 |
5 | public abstract String getName();
6 |
7 | public void onPreExecute(GenericTask task) {
8 | };
9 |
10 | public void onPostExecute(GenericTask task, TaskResult result) {
11 | };
12 |
13 | public void onProgressUpdate(GenericTask task, Object param) {
14 | };
15 |
16 | public void onCancelled(GenericTask task) {
17 | };
18 | }
19 |
--------------------------------------------------------------------------------
/android/src/teaonly/task/TaskListener.java:
--------------------------------------------------------------------------------
1 | package teaonly.task;
2 |
3 | public interface TaskListener {
4 | String getName();
5 |
6 | void onPreExecute(GenericTask task);
7 |
8 | void onPostExecute(GenericTask task, TaskResult result);
9 |
10 | void onProgressUpdate(GenericTask task, Object param);
11 |
12 | void onCancelled(GenericTask task);
13 | }
14 |
--------------------------------------------------------------------------------
/android/src/teaonly/task/TaskParams.java:
--------------------------------------------------------------------------------
1 | package teaonly.task;
2 |
3 | import java.util.HashMap;
4 |
5 | public class TaskParams {
6 |
7 | private HashMap params = null;
8 |
9 | public TaskParams() {
10 | params = new HashMap();
11 | }
12 |
13 | public TaskParams(String key, Object value) {
14 | this();
15 | put(key, value);
16 | }
17 |
18 | public void put(String key, Object value) {
19 | params.put(key, value);
20 | }
21 |
22 | public Object get(String key) {
23 | return params.get(key);
24 | }
25 |
26 | /**
27 | * Get the boolean value associated with a key.
28 | *
29 | * @param key
30 | * A key string.
31 | * @return The truth. if the value is not a Boolean or the String "true" or
32 | * "false". defalut value is false.
33 | */
34 | public boolean getBoolean(String key) {
35 | Object object = get(key);
36 | if (object.equals(Boolean.FALSE)
37 | || (object instanceof String && ((String) object)
38 | .equalsIgnoreCase("false"))) {
39 | return false;
40 | } else if (object.equals(Boolean.TRUE)
41 | || (object instanceof String && ((String) object)
42 | .equalsIgnoreCase("true"))) {
43 | return true;
44 | }
45 | return false;
46 | }
47 |
48 | /**
49 | * Get the double value associated with a key.
50 | *
51 | * @param key
52 | * A key string.
53 | * @return The numeric value. if the value is not a Number object and cannot
54 | * be converted to a number. default value is 0.0.
55 | */
56 | public double getDouble(String key) {
57 | Object object = get(key);
58 | try {
59 | return object instanceof Number ? ((Number) object).doubleValue()
60 | : Double.parseDouble((String) object);
61 | } catch (Exception e) {
62 | return 0.0;
63 | }
64 | }
65 |
66 | /**
67 | * Get the int value associated with a key.
68 | *
69 | * @param key
70 | * A key string.
71 | * @return The integer value. be converted to an integer.
72 | */
73 | public int getInt(String key) {
74 | Object object = get(key);
75 | try {
76 | return object instanceof Number ? ((Number) object).intValue()
77 | : Integer.parseInt((String) object);
78 | } catch (Exception e) {
79 | return 0;
80 | }
81 | }
82 |
83 | /**
84 | * Get the string associated with a key.
85 | *
86 | * @param key
87 | * A key string.
88 | * @return A string which is the value.
89 | */
90 | public String getString(String key) {
91 | Object object = get(key);
92 | return object == null ? null : object.toString();
93 | }
94 |
95 | /**
96 | * Determine if the JSONObject contains a specific key.
97 | *
98 | * @param key
99 | * A key string.
100 | * @return true if the key exists in the JSONObject.
101 | */
102 | public boolean has(String key) {
103 | return this.params.containsKey(key);
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/android/src/teaonly/task/TaskResult.java:
--------------------------------------------------------------------------------
1 | package teaonly.task;
2 |
3 | public enum TaskResult {
4 | OK, FAILED, CANCELLED,
5 |
6 | IO_ERROR,
7 | }
8 |
--------------------------------------------------------------------------------
/desktop/Makefile_linux:
--------------------------------------------------------------------------------
1 | TALK_INC_DIR = ./
2 | EXPAT_INC_DIR = /usr/include
3 | SSL_INC_DIR = /usr/include/openssl
4 | OBJS_DIR = ./obj
5 |
6 | AR = ar
7 | CC = g++
8 | CFLAGS = -Wall -fno-rtti -fno-exceptions -fvisibility=hidden -ffunction-sections -fdata-sections -gdwarf-2 -g3 -O0 -DHAMMER_TIME=1 -DLOGGING=1 -DFEATURE_ENABLE_SSL -DHASHNAMESPACE=__gnu_cxx -DPOSIX -DDISABLE_DYNAMIC_CAST -DHAVE_OPENSSL_SSL_H=1 -D_REENTRANT -DPOSOIX -D_DEBUG -DEXPAT_RELATIVE_PATH -DLINUX -I$(TALK_INC_DIR) -I$(EXPAT_INC_DIR) -I$(SSL_INC_DIR)
9 | LDFLAGS = -lexpat -lssl -lcrypto -lpthread -lrt
10 |
11 | LIB_SRCS =
12 | include libjingle_build.mk
13 | #LIB_OBJS = ${LIB_SRCS:.cc=.o}
14 | LIB_OBJS = ${LIB_SRCS:%.cc=$(OBJS_DIR)/%.o}
15 |
16 |
17 | APP_SRCS =
18 | include app_build.mk
19 | APP_OBJS_ = ${APP_SRCS:%.cpp=$(OBJS_DIR)/%.o}
20 | APP_OBJS = ${APP_OBJS_:%.cc=$(OBJS_DIR)/%.o}
21 |
22 | LIB = libjingle.a
23 | TARGET = SimpleRTC
24 |
25 | $(OBJS_DIR)/%.o : %.c
26 | @mkdir -p $(@D)
27 | $(CC) $(CFLAGS) -c -o $@ $<
28 |
29 | $(OBJS_DIR)/%.o : %.cc
30 | @mkdir -p $(@D)
31 | $(CC) $(CFLAGS) -c -o $@ $<
32 |
33 | $(OBJS_DIR)/%.o : %.cpp
34 | @mkdir -p $(@D)
35 | $(CC) $(CFLAGS) -c -o $@ $<
36 |
37 | $(LIB): $(LIB_OBJS)
38 | $(AR) -cr $@ $(LIB_OBJS)
39 |
40 | $(TARGET): $(LIB) $(APP_OBJS)
41 | $(CC) -o $@ $(APP_OBJS) $(LIB) $(LDFLAGS)
42 |
43 | .PHONY: clean all
44 | all: $(TARGET)
45 | clean:
46 | rm -f $(TARGET)
47 | rm -f $(LIB)
48 | rm -rf $(OBJS_DIR)
49 |
--------------------------------------------------------------------------------
/desktop/Makefile_osx:
--------------------------------------------------------------------------------
1 | TALK_INC_DIR = ./
2 |
3 | AR = ar
4 | CC = g++
5 | CFLAGS = -Wall -arch x86_64 -Xarch_x86_64 -O0 -DHAMMER_TIME=1 -DLOGGING=1 -DFEATURE_ENABLE_SSL -DHASHNAMESPACE=__gnu_cxx -DPOSIX -DDISABLE_DYNAMIC_CAST -DHAVE_OPENSSL_SSL_H=1 -D_REENTRANT -DOSX -D_DEBUG -DEXPAT_RELATIVE_PATH -I$(TALK_INC_DIR)
6 | LDFLAGS = -lexpat -lssl -lcrypto -framework CoreFoundation -framework Carbon -framework Security -framework SystemConfiguration
7 |
8 | OBJS_DIR = ./obj
9 | LIB_SRCS =
10 | include libjingle_build_osx.mk
11 | LIB_OBJS = ${LIB_SRCS:%.cc=$(OBJS_DIR)/%.o}
12 |
13 |
14 | APP_SRCS =
15 | include app_build.mk
16 | APP_OBJS_ = ${APP_SRCS:%.cpp=$(OBJS_DIR)/%.o}
17 | APP_OBJS = ${APP_OBJS_:%.cc=$(OBJS_DIR)/%.o}
18 |
19 | LIB = libjingle.a
20 | TARGET = SimpleRTC
21 |
22 | $(OBJS_DIR)/%.o : %.c
23 | @mkdir -p $(@D)
24 | $(CC) $(CFLAGS) -c -o $@ $<
25 |
26 | $(OBJS_DIR)/%.o : %.cc
27 | @mkdir -p $(@D)
28 | $(CC) $(CFLAGS) -c -o $@ $<
29 |
30 | $(OBJS_DIR)/%.o : %.cpp
31 | @mkdir -p $(@D)
32 | $(CC) $(CFLAGS) -c -o $@ $<
33 |
34 | $(LIB): $(LIB_OBJS)
35 | $(AR) -cr $@ $(LIB_OBJS)
36 |
37 | $(TARGET): $(LIB) $(APP_OBJS)
38 | $(CC) -o $@ $(APP_OBJS) $(LIB) $(LDFLAGS)
39 |
40 | .PHONY: clean all
41 | all: $(TARGET)
42 | clean:
43 | rm -f $(TARGET)
44 | rm -f $(LIB)
45 | rm -rf $(OBJS_DIR)
46 |
--------------------------------------------------------------------------------
/desktop/SimpleRTC.pro:
--------------------------------------------------------------------------------
1 | TARGET = SimpleRTC
2 | QT += network multimedia
3 | CONFIG += console
4 | CONFIG(debug, debug|release) {
5 | DESTDIR = debug
6 | OBJECTS_DIR = debug/obj
7 | MOC_DIR = debug/moc
8 | } else {
9 | DESTDIR = release
10 | OBJECTS_DIR = release/obj
11 | MOC_DIR = release/moc
12 | }
13 |
14 | mac {
15 | FFMPEG_INC_DIR = /Users/teaonly/proj/media/ffmpeg-1.0.1
16 | FFMPEG_AVCODEC_LIBRARY = /Users/teaonly/proj/media/ffmpeg-1.0.1/libavcodec/libavcodec.a
17 | FFMPEG_AVUTIL_LIBRARY = /Users/teaonly/proj/media/ffmpeg-1.0.1/libavutil/libavutil.a
18 | FFMPEG_AVFORMAT_LIBRARY = /Users/teaonly/proj/media/ffmpeg-1.0.1/libavformat/libavformat.a
19 | }
20 |
21 | win32 {
22 | FFMPEG_INC_DIR = "C:\\workspace\\projects\\media\\ffmpeg-dev\\include"
23 | FFMPEG_AVCODEC_LIBRARY = "C:\\workspace\\projects\\media\\ffmpeg-dev\\lib\\avcodec.lib"
24 | FFMPEG_AVUTIL_LIBRARY = "C:\\workspace\\projects\\media\\ffmpeg-dev\\lib\\avutil.lib"
25 | FFMPEG_AVFORMAT_LIBRARY = "C:\\workspace\\projects\\media\\ffmpeg-dev\\lib\\avformat.lib"
26 | }
27 |
28 | INCLUDEPATH += $$ROOT_DIR $$FFMPEG_INC_DIR
29 | DEFINES = "HAMMER_TIME=1" "LOGGING=1" FEATURE_ENABLE_SSL "HASHNAMESPACE=__gnu_cxx" DISABLE_DYNAMIC_CAST "HAVE_OPENSSL_SSL_H=1" _REENTRANT _DEBUG EXPAT_RELATIVE_PATH
30 |
31 | mac {
32 | LIBS += libjingle.a $$FFMPEG_AVCODEC_LIBRARY $$FFMPEG_AVUTIL_LIBRARY $$FFMPEG_AVFORMAT_LIBRARY -lz -framework VideoDecodeAcceleration -framework CoreVideo
33 | DEFINES += POSIX OSX
34 | }
35 |
36 | win32 {
37 | INCLUDEPATH += "C:\\workspace\\projects\\AndroidRTC\\desktop\\win"
38 | LIBS += $$quote(C:/Program Files/Microsoft SDKs/Windows/v6.0A/Lib/shell32.lib)
39 | LIBS += $$quote(C:/Program Files/Microsoft SDKs/Windows/v6.0A/Lib/ws2_32.lib)
40 | LIBS += $$quote(C:/Program Files/Microsoft SDKs/Windows/v6.0A/Lib/crypt32.lib)
41 | LIBS += $$quote(C:/Program Files/Microsoft SDKs/Windows/v6.0A/Lib/iphlpapi.lib)
42 | LIBS += $$quote(C:/Program Files/Microsoft SDKs/Windows/v6.0A/Lib/secur32.lib)
43 | LIBS += $$quote(C:/Program Files/Microsoft SDKs/Windows/v6.0A/Lib/wininet.lib)
44 | LIBS += $$quote(C:/Program Files/Microsoft SDKs/Windows/v6.0A/Lib/advapi32.lib)
45 | LIBS += "C:\\workspace\\projects\\AndroidRTC\\desktop\\win\\Debug\\libjingle.lib"
46 | LIBS += $$FFMPEG_AVCODEC_LIBRARY $$FFMPEG_AVUTIL_LIBRARY
47 | DEFINES += WIN32 _WINDOWS
48 | }
49 |
50 | SOURCES += \
51 | main_gui.cpp \
52 | videowidget.cpp \
53 | videowidgetsurface.cpp \
54 | videodialog.cpp \
55 | media.cpp \
56 | datachannel.cpp \
57 | udpdatachannel.cpp \
58 | mediabuffer.cpp \
59 | rtpsinker.cpp \
60 | ffdecoder.cpp \
61 | ezplayer.cpp \
62 | ezrender.cpp
63 |
64 | HEADERS += \
65 | videowidget.h \
66 | videowidgetsurface.h \
67 | videodialog.h
68 |
69 | FORMS += \
70 | player.ui
71 |
72 |
--------------------------------------------------------------------------------
/desktop/app_build.mk:
--------------------------------------------------------------------------------
1 | APP_SRCS = \
2 | main.cpp \
3 | media.cpp \
4 | datachannel.cpp \
5 | udpdatachannel.cpp \
6 | mediabuffer.cpp\
7 | rtpsinker.cpp
8 |
9 |
--------------------------------------------------------------------------------
/desktop/datachannel.cpp:
--------------------------------------------------------------------------------
1 | #include "udpdatachannel.h"
2 |
3 | DataChannel * CreateChannel(const std::string &type, void *priv) {
4 | if ( type == "udp" ) {
5 | return new UdpDataChannel();
6 | }
7 |
8 | return NULL;
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/desktop/datachannel.h:
--------------------------------------------------------------------------------
1 | #ifndef _DATACHANNEL_H_
2 | #define _DATACHANNEL_H_
3 |
4 | #include "talk/base/sigslot.h"
5 | #include "talk/base/thread.h"
6 | #include "media.h"
7 |
8 | class DataChannel : public sigslot::has_slots<> {
9 | public:
10 | enum State {
11 | STATE_DISCONNECTED = 0,
12 | STATE_CONNECTING = 1,
13 | STATE_LISTENING = 2,
14 | STATE_CONNECTED = 3,
15 | };
16 |
17 | DataChannel(){
18 | state_ = STATE_DISCONNECTED;
19 | }
20 | virtual ~DataChannel(){};
21 |
22 | virtual void Listen(const MediaURL& url) = 0;
23 | virtual void Connect(const MediaURL& url) = 0;
24 | virtual int PushData(const unsigned char * data, size_t len) = 0;
25 | virtual int Close() = 0;
26 |
27 | virtual State GetState() {
28 | return state_;
29 | }
30 |
31 | sigslot::signal2 SignalChannelOpened;
32 | sigslot::signal1 SignalChannelClosed;
33 | sigslot::signal4 SignalDataRead;
34 |
35 | protected:
36 | State state_;
37 | };
38 |
39 | DataChannel * CreateChannel(const std::string &type, void *priv);
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/desktop/ezplayer.cpp:
--------------------------------------------------------------------------------
1 | #include "ffdefine.h"
2 | #include "mediabuffer.h"
3 | #include "rtpsinker.h"
4 | #include "ezplayer.h"
5 | #include "ezrender.h"
6 | #include "ffdecoder.h"
7 |
8 | enum {
9 | MSG_NEW_PACKAGE,
10 | };
11 |
12 | const int kMaxPackageSize = 256*1024;
13 |
14 | EzPlayer::EzPlayer(EzRender* render, talk_base::Thread* decoding_thread) {
15 | render_ = render;
16 | decoding_thread_ = decoding_thread;
17 |
18 | buffer_ = new MediaBuffer(32, kMaxPackageSize);
19 | picture_ = new VideoPicture();
20 | decoder_ = CreateH264Decoder();
21 | }
22 |
23 |
24 | EzPlayer::~EzPlayer() {
25 | if ( decoder_ != NULL) {
26 | delete decoder_;
27 | }
28 | }
29 |
30 | void EzPlayer::OnCodedPicture(RtpSinker* sink, const unsigned char *codedPicture, const unsigned int& length, const unsigned int& timeStamp) {
31 | buffer_->PushBuffer(codedPicture, length);
32 | decoding_thread_->Post(this, MSG_NEW_PACKAGE);
33 | }
34 |
35 | void EzPlayer::OnMessage(talk_base::Message *msg) {
36 | if(msg->message_id == MSG_NEW_PACKAGE ) {
37 | if ( buffer_->PullBuffer() ) {
38 | MediaPackage* pkg = buffer_->Released();
39 | if ( decoder_->DecodeVideoPacket(pkg, picture_) ) {
40 | render_->ShowPicture(picture_);
41 | }
42 | }
43 | }
44 | }
45 |
46 |
47 |
--------------------------------------------------------------------------------
/desktop/ezplayer.h:
--------------------------------------------------------------------------------
1 | #ifndef _EZPLAYER_H_
2 | #define _EZPLAYER_H_
3 |
4 | #include "talk/base/sigslot.h"
5 | #include "talk/base/thread.h"
6 | #include "talk/base/messagequeue.h"
7 | #include "talk/base/criticalsection.h"
8 |
9 | class MediaBuffer;
10 | class VideoPicture;
11 | class EzRender;
12 | class FFDecoder;
13 | class RtpSinker;
14 |
15 | class EzPlayer : public sigslot::has_slots<>, public talk_base::MessageHandler {
16 | public:
17 | EzPlayer(EzRender* render, talk_base::Thread* decoding_thread);
18 | virtual ~EzPlayer();
19 |
20 | void OnCodedPicture(RtpSinker* sink, const unsigned char *codedPicture, const unsigned int& length, const unsigned int& timeStamp);
21 |
22 | protected:
23 | virtual void OnMessage(talk_base::Message *msg);
24 |
25 | private:
26 | EzRender* render_;
27 | talk_base::Thread* decoding_thread_;
28 |
29 | MediaBuffer* buffer_;
30 | VideoPicture* picture_;
31 | FFDecoder* decoder_;
32 | };
33 |
34 | #endif
35 |
36 |
--------------------------------------------------------------------------------
/desktop/ezrender.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "ffdefine.h"
5 | #include "videowidget.h"
6 | #include "ezrender.h"
7 |
8 | EzRender::EzRender( VideoWidget* widget) {
9 | pWidget = widget;
10 |
11 | QAudioFormat format;
12 | // Set up the format, eg.
13 | format.setFrequency(8000);
14 | format.setChannels(1);
15 | format.setSampleSize(8);
16 | format.setCodec("audio/pcm");
17 | format.setByteOrder(QAudioFormat::LittleEndian);
18 | format.setSampleType(QAudioFormat::UnSignedInt);
19 |
20 | QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
21 | if (!info.isFormatSupported(format)) {
22 | printf("raw audio format not supported by backend, cannot play audio.\n");
23 | return;
24 | }
25 |
26 | audio = new QAudioOutput(format);
27 | audio->setBufferSize(128*1024);
28 | pAudioIO = audio->start();
29 | }
30 |
31 | EzRender::~EzRender() {
32 | audio->stop();
33 | delete audio;
34 | }
35 |
36 | #define SATURATE(a,min,max) ((a)<(min)?(min):((a)>(max)?(max):(a)))
37 | static void YUV2RGB(unsigned char inY, unsigned char inU, unsigned char inV, unsigned char *R, unsigned char *G, unsigned char *B)
38 | {
39 | int Gi = 0, Bi = 0;
40 | int Y = 9535*(inY-16);
41 | int U = inU - 128;
42 | int V = inV - 128;
43 | int Ri = (Y + 13074*V) >> 13;
44 | Ri = SATURATE(Ri, 0, 255);
45 | Gi = (Y - 6660*V - 3203*U) >> 13;
46 | Gi = SATURATE(Gi, 0, 255);
47 | Bi = (Y + 16531*U) >> 13;
48 | Bi = SATURATE(Bi, 0, 255);
49 | *R = Ri;
50 | *G = Gi;
51 | *B = Bi;
52 | }
53 |
54 |
55 | void EzRender::ShowPicture(VideoPicture *yuv) {
56 | int vWidth = yuv->width;
57 | int vHeight = yuv->height;
58 |
59 | QImage showedImage( vWidth, vHeight, QImage::Format_RGB32);
60 | for(int i = 0; i < vHeight; i++) {
61 | for(int j = 0; j < vWidth; j++) {
62 | unsigned char Y = *(yuv->vplan[0]+i*yuv->vplan_length[0]+j);
63 | unsigned char U = *(yuv->vplan[1]+i/2*yuv->vplan_length[1] + j/2);
64 | unsigned char V = *(yuv->vplan[2]+i/2*yuv->vplan_length[2] + j/2);
65 | unsigned char R,G,B;
66 |
67 | YUV2RGB(Y,U,V,&R,&G,&B);
68 |
69 | showedImage.setPixel(j,i,qRgb(R,G,B));
70 | }
71 | }
72 | //showedImage.save("./frame.png");
73 |
74 | QVideoFrame frame(showedImage);
75 | if (!frame.isValid())
76 | return;
77 |
78 | QAbstractVideoSurface *surface = pWidget->videoSurface();
79 | QVideoSurfaceFormat currentFormat = surface->surfaceFormat();
80 |
81 | if (frame.pixelFormat() != currentFormat.pixelFormat()
82 | || frame.size() != currentFormat.frameSize()) {
83 | QVideoSurfaceFormat format(frame.size(), frame.pixelFormat());
84 | if (!surface->start(format))
85 | return;
86 | }
87 |
88 | if (!surface->present(frame)) {
89 | surface->stop();
90 | return;
91 | } else {
92 | return;
93 | }
94 |
95 | }
96 |
97 |
98 |
--------------------------------------------------------------------------------
/desktop/ezrender.h:
--------------------------------------------------------------------------------
1 | #ifndef _EZRENDER_H_
2 | #define _EZRENDER_H_
3 |
4 | class VideoWidget;
5 | class QIODevice;
6 | class QAudioOutput;
7 | class VideoPicture;
8 |
9 | class EzRender {
10 | public:
11 | EzRender( VideoWidget* pWidget);
12 | virtual ~EzRender();
13 |
14 | void ShowPicture(VideoPicture *yuv);
15 |
16 | private:
17 | VideoWidget *pWidget;
18 |
19 | QIODevice *pAudioIO;
20 | QAudioOutput *audio;
21 | };
22 |
23 | #endif
24 |
25 |
--------------------------------------------------------------------------------
/desktop/ffdecoder.cpp:
--------------------------------------------------------------------------------
1 | extern "C" {
2 | #include
3 | #include
4 | };
5 |
6 | #include "ffdecoder.h"
7 |
8 | FFDecoder::FFDecoder(AVCodecContext *pCC, AVCodec *pC) {
9 | pCodecCtx = pCC;
10 | pCodec = pC;
11 | pFrame = NULL;
12 |
13 | if ( pCodecCtx->codec_type == AVMEDIA_TYPE_VIDEO) {
14 | type = TEACODEC_TYPE_VIDEO;
15 | pFrame = avcodec_alloc_frame();
16 | }else if ( pCodecCtx->codec_type == AVMEDIA_TYPE_AUDIO)
17 | type = TEACODEC_TYPE_AUDIO;
18 | else
19 | type = TEACODEC_TYPE_UNKNOW;
20 | }
21 |
22 | FFDecoder::~FFDecoder(){
23 | avcodec_close(pCodecCtx);
24 | if ( pFrame != NULL)
25 | av_free(pFrame);
26 | }
27 |
28 | int FFDecoder::DecodeVideoPacket(MediaPackage *pkt, VideoPicture* vp) {
29 | if ( type != TEACODEC_TYPE_VIDEO)
30 | return 0;
31 |
32 |
33 | //convert MediaPakage to FFMPEG's AVPacket
34 | AVPacket ffpkt;
35 | ffpkt.data = pkt->data;
36 | ffpkt.size = pkt->length;
37 | //ffpkt.pts = pkt->pts;
38 | //ffpkt.dts = pkt->dts;
39 |
40 | int isFinished;
41 | avcodec_decode_video2(pCodecCtx, pFrame, &isFinished, &ffpkt);
42 |
43 | if ( !isFinished )
44 | return 0;
45 | vp->video_type = YUV_420_PLAN;
46 | vp->width = pCodecCtx->width;
47 | vp->height = pCodecCtx->height;
48 |
49 | for(int i = 0; i < 3; i++) {
50 | if( (vp->vplan_length[i] != (unsigned int)pFrame->linesize[i]) && (pFrame->linesize[i] > 0) ) {
51 | vp->vplan_length[i] = pFrame->linesize[i];
52 | if ( vp->vplan[i] != NULL ) {
53 | free(vp->vplan[i]);
54 | }
55 | vp->vplan[i] = (unsigned char *)malloc( vp->height * vp->vplan_length[i]);
56 | }
57 | if ( vp->vplan_length[i] > 0) {
58 | assert(vp->vplan[i] != NULL);
59 | if ( i >= 1)
60 | memcpy( vp->vplan[i], pFrame->data[i], vp->height * pFrame->linesize[i] / 2);
61 | else
62 | memcpy( vp->vplan[i], pFrame->data[i], vp->height * pFrame->linesize[i]);
63 | }
64 | }
65 |
66 | return 1;
67 | }
68 |
69 |
70 | FFDecoder* CreateH264Decoder() {
71 | avcodec_register_all();
72 | AVCodec *pC = avcodec_find_decoder(AV_CODEC_ID_H264);
73 | AVCodecContext *pCC = avcodec_alloc_context3(pC);
74 | int ret = avcodec_open2(pCC, pC, NULL);
75 | if ( ret >= 0) {
76 | return new FFDecoder(pCC, pC);
77 | }
78 |
79 | return NULL;
80 | }
81 |
82 |
83 |
--------------------------------------------------------------------------------
/desktop/ffdecoder.h:
--------------------------------------------------------------------------------
1 | #include