Skip to content
Snippets Groups Projects
Commit dd94f023 authored by Leo Ma's avatar Leo Ma Committed by GitHub
Browse files

Merge pull request #531 from tylerjroach/h264

Strip x264 to resolve licensing issues.
parents b7b495ab 84408c34
No related branches found
No related tags found
No related merge requests found
Showing
with 2 additions and 2723 deletions
Loading
Loading
@@ -11,7 +11,6 @@ Feature
 
- [x] Android mini API 16.
- [x] H.264/AAC hard encoding.
- [x] H.264 soft encoding.
- [x] RTMP streaming with state callback handler.
- [x] Portrait and landscape dynamic orientation.
- [x] Front and back cameras hot switch.
Loading
Loading
Loading
Loading
@@ -36,7 +36,6 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
private Button btnPublish;
private Button btnSwitchCamera;
private Button btnRecord;
private Button btnSwitchEncoder;
 
private SharedPreferences sp;
private String rtmpUrl = "rtmp://ossrs.net/" + getRandomAlphaString(3) + '/' + getRandomAlphaDigitString(5);
Loading
Loading
@@ -65,7 +64,6 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
btnPublish = (Button) findViewById(R.id.publish);
btnSwitchCamera = (Button) findViewById(R.id.swCam);
btnRecord = (Button) findViewById(R.id.record);
btnSwitchEncoder = (Button) findViewById(R.id.swEnc);
 
mPublisher = new SrsPublisher((SrsCameraView) findViewById(R.id.glsurfaceview_camera));
mPublisher.setEncodeHandler(new SrsEncodeHandler(this));
Loading
Loading
@@ -87,20 +85,12 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
 
mPublisher.startPublish(rtmpUrl);
mPublisher.startCamera();
if (btnSwitchEncoder.getText().toString().contentEquals("soft encoder")) {
Toast.makeText(getApplicationContext(), "Use hard encoder", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Use soft encoder", Toast.LENGTH_SHORT).show();
}
btnPublish.setText("stop");
btnSwitchEncoder.setEnabled(false);
} else if (btnPublish.getText().toString().contentEquals("stop")) {
mPublisher.stopPublish();
mPublisher.stopRecord();
btnPublish.setText("publish");
btnRecord.setText("record");
btnSwitchEncoder.setEnabled(true);
}
}
});
Loading
Loading
@@ -128,19 +118,6 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
}
}
});
btnSwitchEncoder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (btnSwitchEncoder.getText().toString().contentEquals("soft encoder")) {
mPublisher.switchToSoftEncoder();
btnSwitchEncoder.setText("hard encoder");
} else if (btnSwitchEncoder.getText().toString().contentEquals("hard encoder")) {
mPublisher.switchToHardEncoder();
btnSwitchEncoder.setText("soft encoder");
}
}
});
}
 
@Override
Loading
Loading
@@ -278,7 +255,6 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
mPublisher.stopRecord();
btnPublish.setText("publish");
btnRecord.setText("record");
btnSwitchEncoder.setEnabled(true);
} catch (Exception e1) {
//
}
Loading
Loading
Loading
Loading
@@ -41,16 +41,6 @@
android:layout_alignBottom="@+id/publish"
android:layout_toRightOf="@id/swCam" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="soft encoder"
android:id="@+id/swEnc"
android:layout_alignBottom="@+id/publish"
android:layout_toRightOf="@id/record"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Loading
Loading
Loading
Loading
@@ -5,8 +5,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := libenc
LOCAL_SRC_FILES := libenc.cc
LOCAL_CFLAGS :=
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../libyuv/include $(LOCAL_PATH)/../libx264
LOCAL_STATIC_LIBRARIES := libx264
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../libyuv/include
LOCAL_SHARED_LIBRARIES := libyuv
LOCAL_DISABLE_FORMAT_STRING_CHECKS := true
LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true
Loading
Loading
#include <jni.h>
#include <string.h>
#include <libyuv.h>
#include <x264.h>
 
#include <android/log.h>
 
Loading
Loading
@@ -23,31 +22,9 @@ struct YuvFrame {
uint8_t *v;
};
 
typedef struct x264_context {
// encode parameter
x264_param_t params;
x264_t *encoder;
x264_picture_t picture;
bool global_nal_header;
// input
int width;
int height;
int bitrate;
int fps;
int gop;
char preset[16];
// output
int64_t pts;
int dts;
bool is_key_frame;
} x264_context;
static JavaVM *jvm;
static JNIEnv *jenv;
 
static struct x264_context x264_ctx;
static uint8_t h264_es[1024 * 1024];
static const int SRC_COLOR_FMT = FOURCC_RGBA;
static const int DST_COLOR_FMT = FOURCC_NV12;
 
Loading
Loading
@@ -175,24 +152,6 @@ static bool convert_to_i420_with_crop_scale(uint8_t *src_frame, jint src_width,
return true;
}
 
static void libenc_setEncoderBitrate(JNIEnv *env, jobject thiz, jint bitrate) {
x264_ctx.bitrate = bitrate / 1024; // kbps
}
static void libenc_setEncoderFps(JNIEnv *env, jobject thiz, jint fps) {
x264_ctx.fps = fps;
}
static void libenc_setEncoderGop(JNIEnv *env, jobject thiz, jint gop_size) {
x264_ctx.gop = gop_size;
}
static void libenc_setEncoderPreset(JNIEnv *env, jobject thiz, jstring preset) {
const char *enc_preset = env->GetStringUTFChars(preset, NULL);
strcpy(x264_ctx.preset, enc_preset);
env->ReleaseStringUTFChars(preset, enc_preset);
}
static void
libenc_setEncoderResolution(JNIEnv *env, jobject thiz, jint out_width, jint out_height) {
int y_size = out_width * out_height;
Loading
Loading
@@ -216,9 +175,6 @@ libenc_setEncoderResolution(JNIEnv *env, jobject thiz, jint out_width, jint out_
nv12_frame.u = nv12_frame.y + y_size;
nv12_frame.v = nv12_frame.u + y_size / 4;
}
x264_ctx.width = out_width;
x264_ctx.height = out_height;
}
 
// For COLOR_FormatYUV420Planar
Loading
Loading
@@ -419,142 +375,8 @@ libenc_ARGBToNV12Scaled(JNIEnv *env, jobject thiz, jintArray frame, jint src_wid
return nv12Frame;
}
 
static int encode_nals(const x264_nal_t *nals, int nnal) {
int i;
uint8_t *p = h264_es;
for (i = 0; i < nnal; i++) {
memcpy(p, nals[i].p_payload, nals[i].i_payload);
p += nals[i].i_payload;
}
return p - h264_es;
}
static int encode_global_nal_header() {
int nnal;
x264_nal_t *nals;
x264_ctx.global_nal_header = false;
x264_encoder_headers(x264_ctx.encoder, &nals, &nnal);
return encode_nals(nals, nnal);
}
static int x264_encode(struct YuvFrame *i420_frame, int64_t pts) {
int out_len, nnal;
x264_nal_t *nal;
x264_picture_t pic_out;
int y_size = i420_frame->width * i420_frame->height;
x264_ctx.picture.img.i_csp = X264_CSP_I420;
x264_ctx.picture.img.i_plane = 3;
x264_ctx.picture.img.plane[0] = i420_frame->y;
x264_ctx.picture.img.i_stride[0] = i420_frame->width;
x264_ctx.picture.img.plane[1] = i420_frame->u;
x264_ctx.picture.img.i_stride[1] = i420_frame->width / 2;
x264_ctx.picture.img.plane[2] = i420_frame->v;
x264_ctx.picture.img.i_stride[2] = i420_frame->width / 2;
x264_ctx.picture.i_pts = pts;
x264_ctx.picture.i_type = X264_TYPE_AUTO;
if (x264_encoder_encode(x264_ctx.encoder, &nal, &nnal, &x264_ctx.picture, &pic_out) < 0) {
LIBENC_LOGE("Fail to encode in x264");
return -1;
}
x264_ctx.pts = pic_out.i_pts;
x264_ctx.dts = pic_out.i_dts;
x264_ctx.is_key_frame = pic_out.i_type == X264_TYPE_IDR;
return encode_nals(nal, nnal);
}
static jint libenc_RGBASoftEncode(JNIEnv *env, jobject thiz, jbyteArray frame, jint src_width,
jint src_height, jboolean need_flip, jint rotate_degree,
jlong pts) {
jbyte *rgba_frame = env->GetByteArrayElements(frame, NULL);
if (!convert_to_i420((uint8_t *) rgba_frame, src_width, src_height, need_flip, rotate_degree,
FOURCC_RGBA)) {
return JNI_ERR;
}
int es_len = x264_ctx.global_nal_header ? encode_global_nal_header() : x264_encode(
&i420_scaled_frame, pts);
if (es_len <= 0) {
LIBENC_LOGE("Fail to encode nalu");
return JNI_ERR;
}
jbyteArray outputFrame = env->NewByteArray(es_len);
env->SetByteArrayRegion(outputFrame, 0, es_len, (jbyte *) h264_es);
jclass clz = env->GetObjectClass(thiz);
jmethodID mid = env->GetMethodID(clz, "onSoftEncodedData", "([BJZ)V");
env->CallVoidMethod(thiz, mid, outputFrame, x264_ctx.pts, x264_ctx.is_key_frame);
env->ReleaseByteArrayElements(frame, rgba_frame, JNI_ABORT);
return JNI_OK;
}
static void libenc_closeSoftEncoder(JNIEnv *env, jobject thiz) {
int nnal;
x264_nal_t *nal;
x264_picture_t pic_out;
if (x264_ctx.encoder != NULL) {
while (x264_encoder_delayed_frames(x264_ctx.encoder)) {
x264_encoder_encode(x264_ctx.encoder, &nal, &nnal, NULL, &pic_out);
}
x264_encoder_close(x264_ctx.encoder);
x264_ctx.encoder = NULL;
}
}
static jboolean libenc_openSoftEncoder(JNIEnv *env, jobject thiz) {
// presetting
x264_param_default_preset(&x264_ctx.params, x264_ctx.preset, "zerolatency");
x264_ctx.params.b_repeat_headers = 0;
// for iOS HW decoding
x264_ctx.params.b_sliced_threads = 0;
x264_ctx.global_nal_header = true;
// resolution
x264_ctx.params.i_width = x264_ctx.width;
x264_ctx.params.i_height = x264_ctx.height;
// bitrate
x264_ctx.params.rc.i_bitrate = x264_ctx.bitrate; // kbps
x264_ctx.params.rc.i_rc_method = X264_RC_ABR;
// fps
x264_ctx.params.i_fps_num = x264_ctx.fps;
x264_ctx.params.i_fps_den = 1;
// gop
x264_ctx.params.i_keyint_max = x264_ctx.gop;
if (x264_param_apply_profile(&x264_ctx.params, "baseline") < 0) {
LIBENC_LOGE("Fail to apply profile");
return JNI_FALSE;
}
x264_ctx.encoder = x264_encoder_open(&x264_ctx.params);
if (x264_ctx.encoder == NULL) {
LIBENC_LOGE("Fail to open x264 encoder!");
return JNI_FALSE;
}
return JNI_TRUE;
}
static JNINativeMethod libenc_methods[] = {
{"setEncoderResolution", "(II)V", (void *) libenc_setEncoderResolution},
{"setEncoderFps", "(I)V", (void *) libenc_setEncoderFps},
{"setEncoderGop", "(I)V", (void *) libenc_setEncoderGop},
{"setEncoderBitrate", "(I)V", (void *) libenc_setEncoderBitrate},
{"setEncoderPreset", "(Ljava/lang/String;)V", (void *) libenc_setEncoderPreset},
{"RGBAToI420", "([BIIZI)[B", (void *) libenc_RGBAToI420},
{"RGBAToNV12", "([BIIZI)[B", (void *) libenc_RGBAToNV12},
{"ARGBToI420Scaled", "([IIIZIIIII)[B", (void *) libenc_ARGBToI420Scaled},
Loading
Loading
@@ -562,10 +384,7 @@ static JNINativeMethod libenc_methods[] = {
{"ARGBToI420", "([IIIZI)[B", (void *) libenc_ARGBToI420},
{"ARGBToNV12", "([IIIZI)[B", (void *) libenc_ARGBToNV12},
{"NV21ToNV12Scaled", "([BIIZIIIII)[B", (void *) libenc_NV21ToNV12Scaled},
{"NV21ToI420Scaled", "([BIIZIIIII)[B", (void *) libenc_NV21ToI420Scaled},
{"openSoftEncoder", "()Z", (void *) libenc_openSoftEncoder},
{"closeSoftEncoder", "()V", (void *) libenc_closeSoftEncoder},
{"RGBASoftEncode", "([BIIZIJ)I", (void *) libenc_RGBASoftEncode},
{"NV21ToI420Scaled", "([BIIZIIIII)[B", (void *) libenc_NV21ToI420Scaled}
};
 
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
Loading
Loading
*~
*.a
*.diff
*.orig
*.rej
*.dll*
*.exe
*.def
*.lib
*.pdb
*.mo
*.o
*.patch
*.pc
*.pot
*.so*
*.dylib
.*.swp
.depend
.DS_Store
config.h
config.mak
config.log
x264_config.h
x264
checkasm
*.264
*.h264
*.2pass
*.ffindex
*.avs
*.mkv
*.flv
*.mp4
*.y4m
*.yuv
*.log
*.mbtree
*.temp
*.pyc
*.pgd
*.pgc
.digress_x264
dataDec.txt
log.dec
common/oclobj.h
x264_lookahead.clbin
# Contributors to x264
#
# The format of this file was inspired by the Linux kernel CREDITS file.
# Authors are listed alphabetically.
#
# The fields are: name (N), email (E), web-address (W), CVS account login (C),
# PGP key ID and fingerprint (P), description (D), and snail-mail address (S).
N: Alex Izvorski
E: aizvorski AT gmail DOT com
D: x86 asm (sse2)
N: Alex Wright
E: alexw0885 AT gmail DOT com
D: Motion estimation (subpel and mixed refs)
D: B-RDO
N: bobololo
D: Avisynth input
D: MP4 muxing
N: Christian Heine
E: sennindemokrit AT gmx DOT net
D: x86 asm
N: David Wolstencroft
D: Altivec optimizations
N: Eric Petit
E: eric.petit AT lapsus DOT org
C: titer
D: Altivec asm
D: BeOS and MacOS X ports.
S: France
N: Fiona Glaser
E: fiona AT x264 DOT com
D: Maintainer
D: All areas of encoder analysis and algorithms
D: Motion estimation, rate control, macroblock & frame decisions, RDO, etc
D: x86 asm
S: USA
N: Gabriel Bouvigne
E: bouvigne AT mp3-tech DOT org
D: 2pass VBV
N: Guillaume Poirier
E: gpoirier CHEZ mplayerhq POINT hu
D: Altivec optimizations
S: Brittany, France
N: Henrik Gramner
E: henrik AT gramner DOT com
D: 4:2:2 chroma subsampling, x86 asm, Windows improvements, bugfixes
S: Sweden
N: Laurent Aimar
E: fenrir AT videolan DOT org
C: fenrir
D: Intial import, former maintainer
D: x86 asm (mmx/mmx2)
S: France
N: Loren Merritt
E: pengvado AT akuvian DOT org
C: pengvado
D: Maintainer
D: All areas of encoder analysis and algorithms
D: Motion estimation, rate control, macroblock & frame decisions, RDO, etc
D: Multithreading
D: x86 asm
S: USA
N: Mans Rullgard
E: mru AT mansr DOT com
C: mru
D: Rate control
S: Southampton, UK
N: Michael Niedermayer
E: michaelni AT gmx DOT at
D: Rate control
N: Mike Matsnev
E: mike AT po DOT cs DOT msu DOT su
D: Matroska muxing
N: Min Chen
E: chenm001 AT 163 DOT com
C: chenm001
D: Win32/VC 6.0 port
D: gcc asm to nasm conversion
S: China
N: Radek Czyz
E: radoslaw AT syskin DOT cjb DOT net
D: Cached motion compensation
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libx264
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
LOCAL_SRC_FILES := libs/armeabi-v7a/libx264.a
endif
ifeq ($(TARGET_ARCH_ABI),x86)
LOCAL_SRC_FILES := libs/x86/libx264.a
endif
include $(PREBUILT_STATIC_LIBRARY)
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
# Makefile
include config.mak
vpath %.c $(SRCPATH)
vpath %.h $(SRCPATH)
vpath %.S $(SRCPATH)
vpath %.asm $(SRCPATH)
vpath %.rc $(SRCPATH)
GENERATED =
all: default
default:
SRCS = common/mc.c common/predict.c common/pixel.c common/macroblock.c \
common/frame.c common/dct.c common/cpu.c common/cabac.c \
common/common.c common/osdep.c common/rectangle.c \
common/set.c common/quant.c common/deblock.c common/vlc.c \
common/mvpred.c common/bitstream.c \
encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
encoder/set.c encoder/macroblock.c encoder/cabac.c \
encoder/cavlc.c encoder/encoder.c encoder/lookahead.c
SRCCLI = x264.c input/input.c input/timecode.c input/raw.c input/y4m.c \
output/raw.c output/matroska.c output/matroska_ebml.c \
output/flv.c output/flv_bytestream.c filters/filters.c \
filters/video/video.c filters/video/source.c filters/video/internal.c \
filters/video/resize.c filters/video/cache.c filters/video/fix_vfr_pts.c \
filters/video/select_every.c filters/video/crop.c filters/video/depth.c
SRCSO =
OBJS =
OBJSO =
OBJCLI =
OBJCHK = tools/checkasm.o
OBJEXAMPLE = example.o
CONFIG := $(shell cat config.h)
# GPL-only files
ifneq ($(findstring HAVE_GPL 1, $(CONFIG)),)
SRCCLI +=
endif
# Optional module sources
ifneq ($(findstring HAVE_AVS 1, $(CONFIG)),)
SRCCLI += input/avs.c
endif
ifneq ($(findstring HAVE_THREAD 1, $(CONFIG)),)
SRCCLI += input/thread.c
SRCS += common/threadpool.c
endif
ifneq ($(findstring HAVE_WIN32THREAD 1, $(CONFIG)),)
SRCS += common/win32thread.c
endif
ifneq ($(findstring HAVE_LAVF 1, $(CONFIG)),)
SRCCLI += input/lavf.c
endif
ifneq ($(findstring HAVE_FFMS 1, $(CONFIG)),)
SRCCLI += input/ffms.c
endif
ifneq ($(findstring HAVE_GPAC 1, $(CONFIG)),)
SRCCLI += output/mp4.c
endif
ifneq ($(findstring HAVE_LSMASH 1, $(CONFIG)),)
SRCCLI += output/mp4_lsmash.c
endif
# MMX/SSE optims
ifneq ($(AS),)
X86SRC0 = const-a.asm cabac-a.asm dct-a.asm deblock-a.asm mc-a.asm \
mc-a2.asm pixel-a.asm predict-a.asm quant-a.asm \
cpu-a.asm dct-32.asm bitstream-a.asm
ifneq ($(findstring HIGH_BIT_DEPTH, $(CONFIG)),)
X86SRC0 += sad16-a.asm
else
X86SRC0 += sad-a.asm
endif
X86SRC = $(X86SRC0:%=common/x86/%)
ifeq ($(SYS_ARCH),X86)
ARCH_X86 = yes
ASMSRC = $(X86SRC) common/x86/pixel-32.asm
endif
ifeq ($(SYS_ARCH),X86_64)
ARCH_X86 = yes
ASMSRC = $(X86SRC:-32.asm=-64.asm) common/x86/trellis-64.asm
endif
ifdef ARCH_X86
SRCS += common/x86/mc-c.c common/x86/predict-c.c
OBJASM = $(ASMSRC:%.asm=%.o)
$(OBJASM): common/x86/x86inc.asm common/x86/x86util.asm
OBJCHK += tools/checkasm-a.o
endif
endif
# AltiVec optims
ifeq ($(SYS_ARCH),PPC)
ifneq ($(AS),)
SRCS += common/ppc/mc.c common/ppc/pixel.c common/ppc/dct.c \
common/ppc/quant.c common/ppc/deblock.c \
common/ppc/predict.c
endif
endif
# NEON optims
ifeq ($(SYS_ARCH),ARM)
ifneq ($(AS),)
ASMSRC += common/arm/cpu-a.S common/arm/pixel-a.S common/arm/mc-a.S \
common/arm/dct-a.S common/arm/quant-a.S common/arm/deblock-a.S \
common/arm/predict-a.S common/arm/bitstream-a.S
SRCS += common/arm/mc-c.c common/arm/predict-c.c
OBJASM = $(ASMSRC:%.S=%.o)
OBJCHK += tools/checkasm-arm.o
endif
endif
# AArch64 NEON optims
ifeq ($(SYS_ARCH),AARCH64)
ifneq ($(AS),)
ASMSRC += common/aarch64/bitstream-a.S \
common/aarch64/cabac-a.S \
common/aarch64/dct-a.S \
common/aarch64/deblock-a.S \
common/aarch64/mc-a.S \
common/aarch64/pixel-a.S \
common/aarch64/predict-a.S \
common/aarch64/quant-a.S
SRCS += common/aarch64/asm-offsets.c \
common/aarch64/mc-c.c \
common/aarch64/predict-c.c
OBJASM = $(ASMSRC:%.S=%.o)
OBJCHK += tools/checkasm-aarch64.o
endif
endif
# MSA optims
ifeq ($(SYS_ARCH),MIPS)
ifneq ($(findstring HAVE_MSA 1, $(CONFIG)),)
SRCS += common/mips/mc-c.c common/mips/dct-c.c \
common/mips/deblock-c.c common/mips/pixel-c.c \
common/mips/predict-c.c common/mips/quant-c.c
endif
endif
ifneq ($(HAVE_GETOPT_LONG),1)
SRCCLI += extras/getopt.c
endif
ifeq ($(SYS),WINDOWS)
OBJCLI += $(if $(RC), x264res.o)
ifneq ($(SONAME),)
SRCSO += x264dll.c
OBJSO += $(if $(RC), x264res.dll.o)
endif
endif
ifeq ($(HAVE_OPENCL),yes)
common/oclobj.h: common/opencl/x264-cl.h $(wildcard $(SRCPATH)/common/opencl/*.cl)
cat $^ | $(SRCPATH)/tools/cltostr.sh $@
GENERATED += common/oclobj.h
SRCS += common/opencl.c encoder/slicetype-cl.c
endif
OBJS += $(SRCS:%.c=%.o)
OBJCLI += $(SRCCLI:%.c=%.o)
OBJSO += $(SRCSO:%.c=%.o)
.PHONY: all default fprofiled clean distclean install install-* uninstall cli lib-* etags
cli: x264$(EXE)
lib-static: $(LIBX264)
lib-shared: $(SONAME)
$(LIBX264): $(GENERATED) .depend $(OBJS) $(OBJASM)
rm -f $(LIBX264)
$(AR)$@ $(OBJS) $(OBJASM)
$(if $(RANLIB), $(RANLIB) $@)
$(SONAME): $(GENERATED) .depend $(OBJS) $(OBJASM) $(OBJSO)
$(LD)$@ $(OBJS) $(OBJASM) $(OBJSO) $(SOFLAGS) $(LDFLAGS)
ifneq ($(EXE),)
.PHONY: x264 checkasm example
x264: x264$(EXE)
checkasm: checkasm$(EXE)
example: example$(EXE)
endif
x264$(EXE): $(GENERATED) .depend $(OBJCLI) $(CLI_LIBX264)
$(LD)$@ $(OBJCLI) $(CLI_LIBX264) $(LDFLAGSCLI) $(LDFLAGS)
checkasm$(EXE): $(GENERATED) .depend $(OBJCHK) $(LIBX264)
$(LD)$@ $(OBJCHK) $(LIBX264) $(LDFLAGS)
example$(EXE): $(GENERATED) .depend $(OBJEXAMPLE) $(LIBX264)
$(LD)$@ $(OBJEXAMPLE) $(LIBX264) $(LDFLAGS)
$(OBJS) $(OBJASM) $(OBJSO) $(OBJCLI) $(OBJCHK) $(OBJEXAMPLE): .depend
%.o: %.asm common/x86/x86inc.asm common/x86/x86util.asm
$(AS) $(ASFLAGS) -o $@ $<
-@ $(if $(STRIP), $(STRIP) -x $@) # delete local/anonymous symbols, so they don't show up in oprofile
%.o: %.S
$(AS) $(ASFLAGS) -o $@ $<
-@ $(if $(STRIP), $(STRIP) -x $@) # delete local/anonymous symbols, so they don't show up in oprofile
%.dll.o: %.rc x264.h
$(RC) $(RCFLAGS)$@ -DDLL $<
%.o: %.rc x264.h
$(RC) $(RCFLAGS)$@ $<
.depend: config.mak
@rm -f .depend
@echo 'dependency file generation...'
ifeq ($(COMPILER),CL)
@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS) $(SRCCLI) $(SRCSO)), $(SRCPATH)/tools/msvsdepend.sh "$(CC)" "$(CFLAGS)" "$(SRC)" "$(SRC:$(SRCPATH)/%.c=%.o)" 1>> .depend;)
else
@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS) $(SRCCLI) $(SRCSO)), $(CC) $(CFLAGS) $(SRC) $(DEPMT) $(SRC:$(SRCPATH)/%.c=%.o) $(DEPMM) 1>> .depend;)
endif
config.mak:
./configure
depend: .depend
ifneq ($(wildcard .depend),)
include .depend
endif
SRC2 = $(SRCS) $(SRCCLI)
# These should cover most of the important codepaths
OPT0 = --crf 30 -b1 -m1 -r1 --me dia --no-cabac --direct temporal --ssim --no-weightb
OPT1 = --crf 16 -b2 -m3 -r3 --me hex --no-8x8dct --direct spatial --no-dct-decimate -t0 --slice-max-mbs 50
OPT2 = --crf 26 -b4 -m5 -r2 --me hex --cqm jvt --nr 100 --psnr --no-mixed-refs --b-adapt 2 --slice-max-size 1500
OPT3 = --crf 18 -b3 -m9 -r5 --me umh -t1 -A all --b-pyramid normal --direct auto --no-fast-pskip --no-mbtree
OPT4 = --crf 22 -b3 -m7 -r4 --me esa -t2 -A all --psy-rd 1.0:1.0 --slices 4
OPT5 = --frames 50 --crf 24 -b3 -m10 -r3 --me tesa -t2
OPT6 = --frames 50 -q0 -m9 -r2 --me hex -Aall
OPT7 = --frames 50 -q0 -m2 -r1 --me hex --no-cabac
ifeq (,$(VIDS))
fprofiled:
@echo 'usage: make fprofiled VIDS="infile1 infile2 ..."'
@echo 'where infiles are anything that x264 understands,'
@echo 'i.e. YUV with resolution in the filename, y4m, or avisynth.'
else
fprofiled:
$(MAKE) clean
$(MAKE) x264$(EXE) CFLAGS="$(CFLAGS) $(PROF_GEN_CC)" LDFLAGS="$(LDFLAGS) $(PROF_GEN_LD)"
$(foreach V, $(VIDS), $(foreach I, 0 1 2 3 4 5 6 7, ./x264$(EXE) $(OPT$I) --threads 1 $(V) -o $(DEVNULL) ;))
ifeq ($(COMPILER),CL)
# Because Visual Studio timestamps the object files within the PGD, it fails to build if they change - only the executable should be deleted
rm -f x264$(EXE)
else
rm -f $(SRC2:%.c=%.o)
endif
$(MAKE) CFLAGS="$(CFLAGS) $(PROF_USE_CC)" LDFLAGS="$(LDFLAGS) $(PROF_USE_LD)"
rm -f $(SRC2:%.c=%.gcda) $(SRC2:%.c=%.gcno) *.dyn pgopti.dpi pgopti.dpi.lock *.pgd *.pgc
endif
clean:
rm -f $(OBJS) $(OBJASM) $(OBJCLI) $(OBJSO) $(SONAME) *.a *.lib *.exp *.pdb x264 x264.exe .depend TAGS
rm -f checkasm checkasm.exe $(OBJCHK) $(GENERATED) x264_lookahead.clbin
rm -f example example.exe $(OBJEXAMPLE)
rm -f $(SRC2:%.c=%.gcda) $(SRC2:%.c=%.gcno) *.dyn pgopti.dpi pgopti.dpi.lock *.pgd *.pgc
distclean: clean
rm -f config.mak x264_config.h config.h config.log x264.pc x264.def
rm -rf conftest*
install-cli: cli
$(INSTALL) -d $(DESTDIR)$(bindir)
$(INSTALL) x264$(EXE) $(DESTDIR)$(bindir)
install-lib-dev:
$(INSTALL) -d $(DESTDIR)$(includedir)
$(INSTALL) -d $(DESTDIR)$(libdir)
$(INSTALL) -d $(DESTDIR)$(libdir)/pkgconfig
$(INSTALL) -m 644 $(SRCPATH)/x264.h $(DESTDIR)$(includedir)
$(INSTALL) -m 644 x264_config.h $(DESTDIR)$(includedir)
$(INSTALL) -m 644 x264.pc $(DESTDIR)$(libdir)/pkgconfig
install-lib-static: lib-static install-lib-dev
$(INSTALL) -m 644 $(LIBX264) $(DESTDIR)$(libdir)
$(if $(RANLIB), $(RANLIB) $(DESTDIR)$(libdir)/$(LIBX264))
install-lib-shared: lib-shared install-lib-dev
ifneq ($(IMPLIBNAME),)
$(INSTALL) -d $(DESTDIR)$(bindir)
$(INSTALL) -m 755 $(SONAME) $(DESTDIR)$(bindir)
$(INSTALL) -m 644 $(IMPLIBNAME) $(DESTDIR)$(libdir)
else ifneq ($(SONAME),)
ln -f -s $(SONAME) $(DESTDIR)$(libdir)/libx264.$(SOSUFFIX)
$(INSTALL) -m 755 $(SONAME) $(DESTDIR)$(libdir)
endif
uninstall:
rm -f $(DESTDIR)$(includedir)/x264.h $(DESTDIR)$(includedir)/x264_config.h $(DESTDIR)$(libdir)/libx264.a
rm -f $(DESTDIR)$(bindir)/x264$(EXE) $(DESTDIR)$(libdir)/pkgconfig/x264.pc
ifneq ($(IMPLIBNAME),)
rm -f $(DESTDIR)$(bindir)/$(SONAME) $(DESTDIR)$(libdir)/$(IMPLIBNAME)
else ifneq ($(SONAME),)
rm -f $(DESTDIR)$(libdir)/$(SONAME) $(DESTDIR)$(libdir)/libx264.$(SOSUFFIX)
endif
etags: TAGS
TAGS:
etags $(SRCS)
#!/bin/sh
ANDROID_NDK=$HOME/Android/Sdk/ndk-bundle
SYSROOT=$ANDROID_NDK/platforms/android-21/arch-arm64
CROSS_PREFIX=$ANDROID_NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-
EXTRA_CFLAGS="-march=armv8-a -D__ANDROID__"
EXTRA_LDFLAGS="-nostdlib"
PREFIX=`pwd`/libs/arm64-v8a
./configure --prefix=$PREFIX \
--host=aarch64-linux \
--sysroot=$SYSROOT \
--cross-prefix=$CROSS_PREFIX \
--extra-cflags="$EXTRA_CFLAGS" \
--extra-ldflags="$EXTRA_LDFLAGS" \
--enable-pic \
--enable-static \
--enable-strip \
--disable-cli \
--disable-win32thread \
--disable-avs \
--disable-swscale \
--disable-lavf \
--disable-ffms \
--disable-gpac \
--disable-lsmash
make clean
make STRIP= -j8 install || exit 1
cp -f $PREFIX/lib/libx264.a $PREFIX
rm -rf $PREFIX/include $PREFIX/lib $PREFIX/pkgconfig
#!/bin/sh
ANDROID_NDK=$HOME/Android/Sdk/ndk-bundle
SYSROOT=$ANDROID_NDK/platforms/android-19/arch-arm
CROSS_PREFIX=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
EXTRA_CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=neon -D__ANDROID__ -D__ARM_ARCH_7__ -D__ARM_ARCH_7A__"
EXTRA_LDFLAGS="-nostdlib"
PREFIX=`pwd`/libs/armeabi-v7a
./configure --prefix=$PREFIX \
--host=arm-linux \
--sysroot=$SYSROOT \
--cross-prefix=$CROSS_PREFIX \
--extra-cflags="$EXTRA_CFLAGS" \
--extra-ldflags="$EXTRA_LDFLAGS" \
--enable-pic \
--enable-static \
--enable-strip \
--disable-cli \
--disable-win32thread \
--disable-avs \
--disable-swscale \
--disable-lavf \
--disable-ffms \
--disable-gpac \
--disable-lsmash \
--disable-opencl
make clean
make STRIP= -j8 install || exit 1
cp -f $PREFIX/lib/libx264.a $PREFIX
rm -rf $PREFIX/include $PREFIX/lib $PREFIX/pkgconfig
#!/bin/sh
ANDROID_NDK=$HOME/Android/Sdk/ndk-bundle
SYSROOT=$ANDROID_NDK/platforms/android-19/arch-x86
CROSS_PREFIX=$ANDROID_NDK/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-
EXTRA_CFLAGS="-D__ANDROID__ -D__i686__"
EXTRA_LDFLAGS="-nostdlib"
PREFIX=`pwd`/libs/x86
./configure --prefix=$PREFIX \
--host=i686-linux \
--sysroot=$SYSROOT \
--cross-prefix=$CROSS_PREFIX \
--extra-cflags="$EXTRA_CFLAGS" \
--extra-ldflags="$EXTRA_LDFLAGS" \
--enable-pic \
--enable-static \
--enable-strip \
--disable-cli \
--disable-win32thread \
--disable-avs \
--disable-swscale \
--disable-lavf \
--disable-ffms \
--disable-gpac \
--disable-lsmash \
--disable-opencl \
--disable-asm
make clean
make STRIP= -j8 install || exit 1
cp -f $PREFIX/lib/libx264.a $PREFIX
rm -rf $PREFIX/include $PREFIX/lib $PREFIX/pkgconfig
/*****************************************************************************
* asm-offsets.c: check asm offsets for aarch64
*****************************************************************************
* Copyright (C) 2014-2017 x264 project
*
* Authors: Janne Grunau <janne-x264@jannau.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*
* This program is also available under a commercial proprietary license.
* For more information, contact us at licensing@x264.com.
*****************************************************************************/
#include "common/common.h"
#include "asm-offsets.h"
#define X264_CHECK_OFFSET(s, m, o) struct check_##s##_##m \
{ \
int m_##m[2 * (offsetof(s, m) == o) - 1]; \
}
X264_CHECK_OFFSET(x264_cabac_t, i_low, CABAC_I_LOW);
X264_CHECK_OFFSET(x264_cabac_t, i_range, CABAC_I_RANGE);
X264_CHECK_OFFSET(x264_cabac_t, i_queue, CABAC_I_QUEUE);
X264_CHECK_OFFSET(x264_cabac_t, i_bytes_outstanding, CABAC_I_BYTES_OUTSTANDING);
X264_CHECK_OFFSET(x264_cabac_t, p_start, CABAC_P_START);
X264_CHECK_OFFSET(x264_cabac_t, p, CABAC_P);
X264_CHECK_OFFSET(x264_cabac_t, p_end, CABAC_P_END);
X264_CHECK_OFFSET(x264_cabac_t, f8_bits_encoded, CABAC_F8_BITS_ENCODED);
X264_CHECK_OFFSET(x264_cabac_t, state, CABAC_STATE);
/*****************************************************************************
* asm-offsets.h: asm offsets for aarch64
*****************************************************************************
* Copyright (C) 2014-2017 x264 project
*
* Authors: Janne Grunau <janne-x264@jannau.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*
* This program is also available under a commercial proprietary license.
* For more information, contact us at licensing@x264.com.
*****************************************************************************/
#ifndef X264_AARCH64_ASM_OFFSETS_H
#define X264_AARCH64_ASM_OFFSETS_H
#define CABAC_I_LOW 0x00
#define CABAC_I_RANGE 0x04
#define CABAC_I_QUEUE 0x08
#define CABAC_I_BYTES_OUTSTANDING 0x0c
#define CABAC_P_START 0x10
#define CABAC_P 0x18
#define CABAC_P_END 0x20
#define CABAC_F8_BITS_ENCODED 0x30
#define CABAC_STATE 0x34
#endif
/*****************************************************************************
* asm.S: AArch64 utility macros
*****************************************************************************
* Copyright (C) 2008-2017 x264 project
*
* Authors: Mans Rullgard <mans@mansr.com>
* David Conrad <lessen42@gmail.com>
* Janne Grunau <janne-x264@jannau.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*
* This program is also available under a commercial proprietary license.
* For more information, contact us at licensing@x264.com.
*****************************************************************************/
#include "config.h"
#ifdef PREFIX
# define EXTERN_ASM _
#else
# define EXTERN_ASM
#endif
#ifdef __ELF__
# define ELF
#else
# define ELF #
#endif
#ifdef __MACH__
# define MACH
#else
# define MACH #
#endif
#if HAVE_AS_FUNC
# define FUNC
#else
# define FUNC #
#endif
.macro function name, export=0, align=2
.macro endfunc
ELF .size \name, . - \name
FUNC .endfunc
.purgem endfunc
.endm
.text
.align \align
.if \export
.global EXTERN_ASM\name
ELF .type EXTERN_ASM\name, %function
FUNC .func EXTERN_ASM\name
EXTERN_ASM\name:
.else
ELF .type \name, %function
FUNC .func \name
\name:
.endif
.endm
.macro const name, align=2
.macro endconst
ELF .size \name, . - \name
.purgem endconst
.endm
ELF .section .rodata
MACH .const_data
.align \align
\name:
.endm
.macro movrel rd, val
#if defined(PIC) && defined(__APPLE__)
adrp \rd, \val@PAGE
add \rd, \rd, \val@PAGEOFF
#elif defined(PIC)
adrp \rd, \val
add \rd, \rd, :lo12:\val
#else
ldr \rd, =\val
#endif
.endm
#define GLUE(a, b) a ## b
#define JOIN(a, b) GLUE(a, b)
#define X(s) JOIN(EXTERN_ASM, s)
#define FDEC_STRIDE 32
#define FENC_STRIDE 16
.macro SUMSUB_AB sum, sub, a, b
add \sum, \a, \b
sub \sub, \a, \b
.endm
.macro unzip t1, t2, s1, s2
uzp1 \t1, \s1, \s2
uzp2 \t2, \s1, \s2
.endm
.macro transpose t1, t2, s1, s2
trn1 \t1, \s1, \s2
trn2 \t2, \s1, \s2
.endm
.macro transpose4x4.h v0, v1, v2, v3, t0, t1, t2, t3
transpose \t0\().2s, \t2\().2s, \v0\().2s, \v2\().2s
transpose \t1\().2s, \t3\().2s, \v1\().2s, \v3\().2s
transpose \v0\().4h, \v1\().4h, \t0\().4h, \t1\().4h
transpose \v2\().4h, \v3\().4h, \t2\().4h, \t3\().4h
.endm
.macro transpose4x8.h v0, v1, v2, v3, t0, t1, t2, t3
transpose \t0\().4s, \t2\().4s, \v0\().4s, \v2\().4s
transpose \t1\().4s, \t3\().4s, \v1\().4s, \v3\().4s
transpose \v0\().8h, \v1\().8h, \t0\().8h, \t1\().8h
transpose \v2\().8h, \v3\().8h, \t2\().8h, \t3\().8h
.endm
.macro transpose8x8.h r0, r1, r2, r3, r4, r5, r6, r7, r8, r9
trn1 \r8\().8H, \r0\().8H, \r1\().8H
trn2 \r9\().8H, \r0\().8H, \r1\().8H
trn1 \r1\().8H, \r2\().8H, \r3\().8H
trn2 \r3\().8H, \r2\().8H, \r3\().8H
trn1 \r0\().8H, \r4\().8H, \r5\().8H
trn2 \r5\().8H, \r4\().8H, \r5\().8H
trn1 \r2\().8H, \r6\().8H, \r7\().8H
trn2 \r7\().8H, \r6\().8H, \r7\().8H
trn1 \r4\().4S, \r0\().4S, \r2\().4S
trn2 \r2\().4S, \r0\().4S, \r2\().4S
trn1 \r6\().4S, \r5\().4S, \r7\().4S
trn2 \r7\().4S, \r5\().4S, \r7\().4S
trn1 \r5\().4S, \r9\().4S, \r3\().4S
trn2 \r9\().4S, \r9\().4S, \r3\().4S
trn1 \r3\().4S, \r8\().4S, \r1\().4S
trn2 \r8\().4S, \r8\().4S, \r1\().4S
trn1 \r0\().2D, \r3\().2D, \r4\().2D
trn2 \r4\().2D, \r3\().2D, \r4\().2D
trn1 \r1\().2D, \r5\().2D, \r6\().2D
trn2 \r5\().2D, \r5\().2D, \r6\().2D
trn2 \r6\().2D, \r8\().2D, \r2\().2D
trn1 \r2\().2D, \r8\().2D, \r2\().2D
trn1 \r3\().2D, \r9\().2D, \r7\().2D
trn2 \r7\().2D, \r9\().2D, \r7\().2D
.endm
.macro transpose_8x16.b r0, r1, r2, r3, r4, r5, r6, r7, t0, t1
trn1 \t0\().16b, \r0\().16b, \r1\().16b
trn2 \t1\().16b, \r0\().16b, \r1\().16b
trn1 \r1\().16b, \r2\().16b, \r3\().16b
trn2 \r3\().16b, \r2\().16b, \r3\().16b
trn1 \r0\().16b, \r4\().16b, \r5\().16b
trn2 \r5\().16b, \r4\().16b, \r5\().16b
trn1 \r2\().16b, \r6\().16b, \r7\().16b
trn2 \r7\().16b, \r6\().16b, \r7\().16b
trn1 \r4\().8h, \r0\().8h, \r2\().8h
trn2 \r2\().8h, \r0\().8h, \r2\().8h
trn1 \r6\().8h, \r5\().8h, \r7\().8h
trn2 \r7\().8h, \r5\().8h, \r7\().8h
trn1 \r5\().8h, \t1\().8h, \r3\().8h
trn2 \t1\().8h, \t1\().8h, \r3\().8h
trn1 \r3\().8h, \t0\().8h, \r1\().8h
trn2 \t0\().8h, \t0\().8h, \r1\().8h
trn1 \r0\().4s, \r3\().4s, \r4\().4s
trn2 \r4\().4s, \r3\().4s, \r4\().4s
trn1 \r1\().4s, \r5\().4s, \r6\().4s
trn2 \r5\().4s, \r5\().4s, \r6\().4s
trn2 \r6\().4s, \t0\().4s, \r2\().4s
trn1 \r2\().4s, \t0\().4s, \r2\().4s
trn1 \r3\().4s, \t1\().4s, \r7\().4s
trn2 \r7\().4s, \t1\().4s, \r7\().4s
.endm
.macro transpose_4x16.b r0, r1, r2, r3, t4, t5, t6, t7
trn1 \t4\().16b, \r0\().16b, \r1\().16b
trn2 \t5\().16b, \r0\().16b, \r1\().16b
trn1 \t6\().16b, \r2\().16b, \r3\().16b
trn2 \t7\().16b, \r2\().16b, \r3\().16b
trn1 \r0\().8h, \t4\().8h, \t6\().8h
trn2 \r2\().8h, \t4\().8h, \t6\().8h
trn1 \r1\().8h, \t5\().8h, \t7\().8h
trn2 \r3\().8h, \t5\().8h, \t7\().8h
.endm
.macro transpose_4x8.b r0, r1, r2, r3, t4, t5, t6, t7
trn1 \t4\().8b, \r0\().8b, \r1\().8b
trn2 \t5\().8b, \r0\().8b, \r1\().8b
trn1 \t6\().8b, \r2\().8b, \r3\().8b
trn2 \t7\().8b, \r2\().8b, \r3\().8b
trn1 \r0\().4h, \t4\().4h, \t6\().4h
trn2 \r2\().4h, \t4\().4h, \t6\().4h
trn1 \r1\().4h, \t5\().4h, \t7\().4h
trn2 \r3\().4h, \t5\().4h, \t7\().4h
.endm
/*****************************************************************************
* bitstream-a.S: aarch64 bitstream functions
*****************************************************************************
* Copyright (C) 2014-2017 x264 project
*
* Authors: Janne Grunau <janne-x264@jannau.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*
* This program is also available under a commercial proprietary license.
* For more information, contact us at licensing@x264.com.
*****************************************************************************/
#include "asm.S"
function x264_nal_escape_neon, export=1
movi v0.16b, #0xff
movi v4.16b, #4
mov w3, #3
subs x6, x1, x2
cbz x6, 99f
0:
cmn x6, #15
b.lt 16f
mov x1, x2
b 100f
16:
ld1 {v1.16b}, [x1], #16
ext v2.16b, v0.16b, v1.16b, #14
ext v3.16b, v0.16b, v1.16b, #15
cmhi v7.16b, v4.16b, v1.16b
cmeq v5.16b, v2.16b, #0
cmeq v6.16b, v3.16b, #0
and v5.16b, v5.16b, v7.16b
and v5.16b, v5.16b, v6.16b
shrn v7.8b, v5.8h, #4
mov x7, v7.d[0]
cbz x7, 16f
mov x6, #-16
100:
umov w5, v0.b[14]
umov w4, v0.b[15]
orr w5, w4, w5, lsl #8
101:
ldrb w4, [x1, x6]
orr w9, w4, w5, lsl #16
cmp w9, #3
b.hi 102f
strb w3, [x0], #1
orr w5, w3, w5, lsl #8
102:
adds x6, x6, #1
strb w4, [x0], #1
orr w5, w4, w5, lsl #8
b.lt 101b
subs x6, x1, x2
lsr w9, w5, #8
mov v0.b[14], w9
mov v0.b[15], w5
b.lt 0b
ret
16:
subs x6, x1, x2
st1 {v1.16b}, [x0], #16
mov v0.16b, v1.16b
b.lt 0b
99:
ret
endfunc
/*****************************************************************************
* cabac-a.S: aarch64 cabac
*****************************************************************************
* Copyright (C) 2014-2017 x264 project
*
* Authors: Janne Grunau <janne-x264@jannau.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*
* This program is also available under a commercial proprietary license.
* For more information, contact us at licensing@x264.com.
*****************************************************************************/
#include "asm.S"
#include "asm-offsets.h"
// w11 holds x264_cabac_t.i_low
// w12 holds x264_cabac_t.i_range
function x264_cabac_encode_decision_asm, export=1
movrel x8, X(x264_cabac_range_lps)
movrel x9, X(x264_cabac_transition)
add w10, w1, #CABAC_STATE
ldrb w3, [x0, x10] // i_state
ldr w12, [x0, #CABAC_I_RANGE]
and x4, x3, #~1
asr w5, w12, #6
add x8, x8, x4, lsl #1
sub w5, w5, #4
eor w6, w2, w3 // b ^ i_state
ldrb w4, [x8, x5] // i_range_lps
ldr w11, [x0, #CABAC_I_LOW]
sub w12, w12, w4
tbz w6, #0, 1f // (b ^ i_state) & 1
add w11, w11, w12
mov w12, w4
1:
orr w4, w2, w3, lsl #1
ldrb w9, [x9, x4]
strb w9, [x0, x10] // i_state
cabac_encode_renorm:
clz w5, w12
ldr w2, [x0, #CABAC_I_QUEUE]
sub w5, w5, #23
lsl w12, w12, w5
lsl w11, w11, w5
2:
adds w2, w2, w5
str w12, [x0, #CABAC_I_RANGE]
b.lt 0f
cabac_putbyte:
mov w13, #0x400
add w12, w2, #10
lsl w13, w13, w2
asr w4, w11, w12 // out
sub w2, w2, #8
sub w13, w13, #1
subs w5, w4, #0xff
and w11, w11, w13
ldr w6, [x0, #CABAC_I_BYTES_OUTSTANDING]
str w2, [x0, #CABAC_I_QUEUE]
b.ne 1f
add w6, w6, #1
str w11, [x0, #CABAC_I_LOW]
str w6, [x0, #CABAC_I_BYTES_OUTSTANDING]
ret
1:
ldr x7, [x0, #CABAC_P]
asr w5, w4, #8 // carry
ldrb w8, [x7, #-1]
add w8, w8, w5
sub w5, w5, #1
strb w8, [x7, #-1]
cbz w6, 3f
2:
subs w6, w6, #1
strb w5, [x7], #1
b.gt 2b
3:
strb w4, [x7], #1
str wzr, [x0, #CABAC_I_BYTES_OUTSTANDING]
str x7, [x0, #CABAC_P]
0:
str w11, [x0, #CABAC_I_LOW]
str w2, [x0, #CABAC_I_QUEUE]
ret
endfunc
function x264_cabac_encode_bypass_asm, export=1
ldr w12, [x0, #CABAC_I_RANGE]
ldr w11, [x0, #CABAC_I_LOW]
ldr w2, [x0, #CABAC_I_QUEUE]
and w1, w1, w12
add w11, w1, w11, lsl #1
adds w2, w2, #1
b.ge cabac_putbyte
str w11, [x0, #CABAC_I_LOW]
str w2, [x0, #CABAC_I_QUEUE]
ret
endfunc
function x264_cabac_encode_terminal_asm, export=1
ldr w12, [x0, #CABAC_I_RANGE]
ldr w11, [x0, #CABAC_I_LOW]
sub w12, w12, #2
b cabac_encode_renorm
endfunc
This diff is collapsed.
/*****************************************************************************
* dct.h: aarch64 transform and zigzag
*****************************************************************************
* Copyright (C) 2009-2017 x264 project
*
* Authors: David Conrad <lessen42@gmail.com>
* Janne Grunau <janne-x264@jannau.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*
* This program is also available under a commercial proprietary license.
* For more information, contact us at licensing@x264.com.
*****************************************************************************/
#ifndef X264_AARCH64_DCT_H
#define X264_AARCH64_DCT_H
void x264_dct4x4dc_neon( int16_t d[16] );
void x264_idct4x4dc_neon( int16_t d[16] );
void x264_sub4x4_dct_neon( int16_t dct[16], uint8_t *pix1, uint8_t *pix2 );
void x264_sub8x8_dct_neon( int16_t dct[4][16], uint8_t *pix1, uint8_t *pix2 );
void x264_sub16x16_dct_neon( int16_t dct[16][16], uint8_t *pix1, uint8_t *pix2 );
void x264_add4x4_idct_neon( uint8_t *p_dst, int16_t dct[16] );
void x264_add8x8_idct_neon( uint8_t *p_dst, int16_t dct[4][16] );
void x264_add16x16_idct_neon( uint8_t *p_dst, int16_t dct[16][16] );
void x264_add8x8_idct_dc_neon( uint8_t *p_dst, int16_t dct[4] );
void x264_add16x16_idct_dc_neon( uint8_t *p_dst, int16_t dct[16] );
void x264_sub8x8_dct_dc_neon( int16_t dct[4], uint8_t *pix1, uint8_t *pix2 );
void x264_sub8x16_dct_dc_neon( int16_t dct[8], uint8_t *pix1, uint8_t *pix2 );
void x264_sub8x8_dct8_neon( int16_t dct[64], uint8_t *pix1, uint8_t *pix2 );
void x264_sub16x16_dct8_neon( int16_t dct[4][64], uint8_t *pix1, uint8_t *pix2 );
void x264_add8x8_idct8_neon( uint8_t *p_dst, int16_t dct[64] );
void x264_add16x16_idct8_neon( uint8_t *p_dst, int16_t dct[4][64] );
void x264_zigzag_scan_4x4_frame_neon( int16_t level[16], int16_t dct[16] );
void x264_zigzag_scan_4x4_field_neon( int16_t level[16], int16_t dct[16] );
void x264_zigzag_scan_8x8_frame_neon( int16_t level[64], int16_t dct[64] );
void x264_zigzag_scan_8x8_field_neon( int16_t level[64], int16_t dct[64] );
int x264_zigzag_sub_4x4_field_neon( dctcoef level[16], const pixel *p_src, pixel *p_dst );
int x264_zigzag_sub_4x4ac_field_neon( dctcoef level[16], const pixel *p_src, pixel *p_dst, dctcoef *dc );
int x264_zigzag_sub_4x4_frame_neon( dctcoef level[16], const pixel *p_src, pixel *p_dst );
int x264_zigzag_sub_4x4ac_frame_neon( dctcoef level[16], const pixel *p_src, pixel *p_dst, dctcoef *dc );
int x264_zigzag_sub_8x8_field_neon( dctcoef level[16], const pixel *p_src, pixel *p_dst );
int x264_zigzag_sub_8x8_frame_neon( dctcoef level[16], const pixel *p_src, pixel *p_dst );
void x264_zigzag_interleave_8x8_cavlc_neon( dctcoef *dst, dctcoef *src, uint8_t *nnz );
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment