* hexene/scratchpad:
Move & Rename buildscript, remove tabs
Fix regular build
Support (H/W accelerated) H.264 decoding on Android via Stagefright
Add build-script for Android
C++ Support ;)
Conflicts:
Changelog
Makefile
configure
libavcodec/Makefile
libavcodec/allcodecs.c
libavcodec/version.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
| ... | ... |
@@ -2,13 +2,13 @@ MAIN_MAKEFILE=1 |
| 2 | 2 |
include config.mak |
| 3 | 3 |
|
| 4 | 4 |
vpath %.c $(SRC_PATH) |
| 5 |
+vpath %.cpp $(SRC_PATH) |
|
| 5 | 6 |
vpath %.h $(SRC_PATH) |
| 6 | 7 |
vpath %.S $(SRC_PATH) |
| 7 | 8 |
vpath %.asm $(SRC_PATH) |
| 8 | 9 |
vpath %.v $(SRC_PATH) |
| 9 | 10 |
vpath %.texi $(SRC_PATH) |
| 10 | 11 |
|
| 11 |
- |
|
| 12 | 12 |
PROGS-$(CONFIG_FFMPEG) += ffmpeg |
| 13 | 13 |
PROGS-$(CONFIG_AVCONV) += avconv |
| 14 | 14 |
PROGS-$(CONFIG_FFPLAY) += ffplay |
| ... | ... |
@@ -10,7 +10,7 @@ ifndef SUBDIR |
| 10 | 10 |
ifndef V |
| 11 | 11 |
Q = @ |
| 12 | 12 |
ECHO = printf "$(1)\t%s\n" $(2) |
| 13 |
-BRIEF = CC AS YASM AR LD HOSTCC STRIP CP |
|
| 13 |
+BRIEF = CC CXX AS YASM AR LD HOSTCC STRIP CP |
|
| 14 | 14 |
SILENT = DEPCC YASMDEP RM RANLIB |
| 15 | 15 |
MSG = $@ |
| 16 | 16 |
M = @$(call ECHO,$(TAG),$@); |
| ... | ... |
@@ -27,6 +27,7 @@ IFLAGS := -I. -I$(SRC_PATH)/ |
| 27 | 27 |
CPPFLAGS := $(IFLAGS) $(CPPFLAGS) |
| 28 | 28 |
CFLAGS += $(ECFLAGS) |
| 29 | 29 |
CCFLAGS = $(CFLAGS) |
| 30 |
+CXXFLAGS := $(CFLAGS) $(CXXFLAGS) |
|
| 30 | 31 |
YASMFLAGS += $(IFLAGS) -I$(SRC_PATH)/libavutil/x86/ -Pconfig.asm |
| 31 | 32 |
HOSTCFLAGS += $(IFLAGS) |
| 32 | 33 |
LDFLAGS := $(ALLFFLIBS:%=-Llib%) $(LDFLAGS) |
| ... | ... |
@@ -37,11 +38,15 @@ define COMPILE |
| 37 | 37 |
endef |
| 38 | 38 |
|
| 39 | 39 |
COMPILE_C = $(call COMPILE,CC) |
| 40 |
+COMPILE_CXX = $(call COMPILE,CXX) |
|
| 40 | 41 |
COMPILE_S = $(call COMPILE,AS) |
| 41 | 42 |
|
| 42 | 43 |
%.o: %.c |
| 43 | 44 |
$(COMPILE_C) |
| 44 | 45 |
|
| 46 |
+%.o: %.cpp |
|
| 47 |
+ $(COMPILE_CXX) |
|
| 48 |
+ |
|
| 45 | 49 |
%.o: %.S |
| 46 | 50 |
$(COMPILE_S) |
| 47 | 51 |
|
| ... | ... |
@@ -179,6 +179,7 @@ External library support: |
| 179 | 179 |
--enable-librtmp enable RTMP[E] support via librtmp [no] |
| 180 | 180 |
--enable-libschroedinger enable Dirac support via libschroedinger [no] |
| 181 | 181 |
--enable-libspeex enable Speex encoding and decoding via libspeex [no] |
| 182 |
+ --enable-libstagefright-h264 enable H.264 decoding via libstagefright [no] |
|
| 182 | 183 |
--enable-libtheora enable Theora encoding via libtheora [no] |
| 183 | 184 |
--enable-libvo-aacenc enable AAC encoding via libvo-aacenc [no] |
| 184 | 185 |
--enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no] |
| ... | ... |
@@ -205,12 +206,14 @@ Advanced options (experts only): |
| 205 | 205 |
--ar=AR use archive tool AR [$ar_default] |
| 206 | 206 |
--as=AS use assembler AS [$as_default] |
| 207 | 207 |
--cc=CC use C compiler CC [$cc_default] |
| 208 |
+ --cxx=CXX use C compiler CXX [$cxx_default] |
|
| 208 | 209 |
--ld=LD use linker LD |
| 209 | 210 |
--host-cc=HOSTCC use host C compiler HOSTCC |
| 210 | 211 |
--host-cflags=HCFLAGS use HCFLAGS when compiling for host |
| 211 | 212 |
--host-ldflags=HLDFLAGS use HLDFLAGS when linking for host |
| 212 | 213 |
--host-libs=HLIBS use libs HLIBS when linking for host |
| 213 | 214 |
--extra-cflags=ECFLAGS add ECFLAGS to CFLAGS [$CFLAGS] |
| 215 |
+ --extra-cxxflags=ECFLAGS add ECFLAGS to CXXFLAGS [$CXXFLAGS] |
|
| 214 | 216 |
--extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS] |
| 215 | 217 |
--extra-libs=ELIBS add ELIBS [$ELIBS] |
| 216 | 218 |
--extra-version=STRING version string suffix [] |
| ... | ... |
@@ -582,6 +585,10 @@ add_cflags(){
|
| 582 | 582 |
append CFLAGS $($filter_cflags "$@") |
| 583 | 583 |
} |
| 584 | 584 |
|
| 585 |
+add_cxxflags(){
|
|
| 586 |
+ append CXXFLAGS $($filter_cflags "$@") |
|
| 587 |
+} |
|
| 588 |
+ |
|
| 585 | 589 |
add_asflags(){
|
| 586 | 590 |
append ASFLAGS $($filter_asflags "$@") |
| 587 | 591 |
} |
| ... | ... |
@@ -606,6 +613,13 @@ check_cc(){
|
| 606 | 606 |
check_cmd $cc $CPPFLAGS $CFLAGS "$@" -c -o $TMPO $TMPC |
| 607 | 607 |
} |
| 608 | 608 |
|
| 609 |
+check_cxx(){
|
|
| 610 |
+ log check_cxx "$@" |
|
| 611 |
+ cat > $TMPCPP |
|
| 612 |
+ log_file $TMPCPP |
|
| 613 |
+ check_cmd $cxx $CPPFLAGS $CFLAGS $CXXFLAGS "$@" -c -o $TMPO $TMPCPP |
|
| 614 |
+} |
|
| 615 |
+ |
|
| 609 | 616 |
check_cpp(){
|
| 610 | 617 |
log check_cpp "$@" |
| 611 | 618 |
cat > $TMPC |
| ... | ... |
@@ -641,12 +655,14 @@ check_yasm(){
|
| 641 | 641 |
|
| 642 | 642 |
check_ld(){
|
| 643 | 643 |
log check_ld "$@" |
| 644 |
+ type=$1 |
|
| 645 |
+ shift 1 |
|
| 644 | 646 |
flags='' |
| 645 | 647 |
libs='' |
| 646 | 648 |
for f; do |
| 647 | 649 |
test "${f}" = "${f#-l}" && flags="$flags $f" || libs="$libs $f"
|
| 648 | 650 |
done |
| 649 |
- check_cc $($filter_cflags $flags) || return |
|
| 651 |
+ check_$type $($filter_cflags $flags) || return |
|
| 650 | 652 |
check_cmd $ld $LDFLAGS $flags -o $TMPE $TMPO $libs $extralibs |
| 651 | 653 |
} |
| 652 | 654 |
|
| ... | ... |
@@ -666,9 +682,17 @@ int x; |
| 666 | 666 |
EOF |
| 667 | 667 |
} |
| 668 | 668 |
|
| 669 |
+check_cxxflags(){
|
|
| 670 |
+ log check_cxxflags "$@" |
|
| 671 |
+ set -- $($filter_cflags "$@") |
|
| 672 |
+ check_cxx "$@" <<EOF && append CXXFLAGS "$@" |
|
| 673 |
+int x; |
|
| 674 |
+EOF |
|
| 675 |
+} |
|
| 676 |
+ |
|
| 669 | 677 |
test_ldflags(){
|
| 670 | 678 |
log test_ldflags "$@" |
| 671 |
- check_ld "$@" <<EOF |
|
| 679 |
+ check_ld "cc" "$@" <<EOF |
|
| 672 | 680 |
int main(void){ return 0; }
|
| 673 | 681 |
EOF |
| 674 | 682 |
} |
| ... | ... |
@@ -694,7 +718,7 @@ check_func(){
|
| 694 | 694 |
func=$1 |
| 695 | 695 |
shift |
| 696 | 696 |
disable $func |
| 697 |
- check_ld "$@" <<EOF && enable $func |
|
| 697 |
+ check_ld "cc" "$@" <<EOF && enable $func |
|
| 698 | 698 |
extern int $func(); |
| 699 | 699 |
int main(void){ $func(); }
|
| 700 | 700 |
EOF |
| ... | ... |
@@ -705,7 +729,7 @@ check_mathfunc(){
|
| 705 | 705 |
func=$1 |
| 706 | 706 |
shift |
| 707 | 707 |
disable $func |
| 708 |
- check_ld "$@" <<EOF && enable $func |
|
| 708 |
+ check_ld "cc" "$@" <<EOF && enable $func |
|
| 709 | 709 |
#include <math.h> |
| 710 | 710 |
float foo(float f) { return $func(f); }
|
| 711 | 711 |
int main(void){ return (int) foo; }
|
| ... | ... |
@@ -725,7 +749,26 @@ check_func_headers(){
|
| 725 | 725 |
echo "long check_$func(void) { return (long) $func; }"
|
| 726 | 726 |
done |
| 727 | 727 |
echo "int main(void) { return 0; }"
|
| 728 |
- } | check_ld "$@" && enable $funcs && enable_safe $headers |
|
| 728 |
+ } | check_ld "cc" "$@" && enable $funcs && enable_safe $headers |
|
| 729 |
+} |
|
| 730 |
+ |
|
| 731 |
+check_class_headers_cpp(){
|
|
| 732 |
+ log check_class_headers_cpp "$@" |
|
| 733 |
+ headers=$1 |
|
| 734 |
+ classes=$2 |
|
| 735 |
+ shift 2 |
|
| 736 |
+ {
|
|
| 737 |
+ for hdr in $headers; do |
|
| 738 |
+ echo "#include <$hdr>" |
|
| 739 |
+ done |
|
| 740 |
+ echo "int main(void) { "
|
|
| 741 |
+ i=1 |
|
| 742 |
+ for class in $classes; do |
|
| 743 |
+ echo "$class obj$i;" |
|
| 744 |
+ i=$(expr $i + 1) |
|
| 745 |
+ done |
|
| 746 |
+ echo "return 0; }" |
|
| 747 |
+ } | check_ld "cxx" "$@" && enable $funcs && enable_safe $headers |
|
| 729 | 748 |
} |
| 730 | 749 |
|
| 731 | 750 |
check_cpp_condition(){
|
| ... | ... |
@@ -757,6 +800,14 @@ check_lib2(){
|
| 757 | 757 |
check_func_headers "$headers" "$funcs" "$@" && add_extralibs "$@" |
| 758 | 758 |
} |
| 759 | 759 |
|
| 760 |
+check_lib_cpp(){
|
|
| 761 |
+ log check_lib_cpp "$@" |
|
| 762 |
+ headers="$1" |
|
| 763 |
+ classes="$2" |
|
| 764 |
+ shift 2 |
|
| 765 |
+ check_class_headers_cpp "$headers" "$classes" "$@" && add_extralibs "$@" |
|
| 766 |
+} |
|
| 767 |
+ |
|
| 760 | 768 |
check_pkg_config(){
|
| 761 | 769 |
log check_pkg_config "$@" |
| 762 | 770 |
pkg="$1" |
| ... | ... |
@@ -772,7 +823,7 @@ check_pkg_config(){
|
| 772 | 772 |
} |
| 773 | 773 |
|
| 774 | 774 |
check_exec(){
|
| 775 |
- check_ld "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
|
|
| 775 |
+ check_ld "cc" "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
|
|
| 776 | 776 |
} |
| 777 | 777 |
|
| 778 | 778 |
check_exec_crash(){
|
| ... | ... |
@@ -852,6 +903,14 @@ require2(){
|
| 852 | 852 |
check_lib2 "$headers" $func "$@" || die "ERROR: $name not found" |
| 853 | 853 |
} |
| 854 | 854 |
|
| 855 |
+require_cpp(){
|
|
| 856 |
+ name="$1" |
|
| 857 |
+ headers="$2" |
|
| 858 |
+ classes="$3" |
|
| 859 |
+ shift 3 |
|
| 860 |
+ check_lib_cpp "$headers" "$classes" "$@" || die "ERROR: $name not found" |
|
| 861 |
+} |
|
| 862 |
+ |
|
| 855 | 863 |
require_pkg_config(){
|
| 856 | 864 |
pkg="$1" |
| 857 | 865 |
check_pkg_config "$@" || die "ERROR: $pkg not found" |
| ... | ... |
@@ -947,6 +1006,7 @@ CONFIG_LIST=" |
| 947 | 947 |
librtmp |
| 948 | 948 |
libschroedinger |
| 949 | 949 |
libspeex |
| 950 |
+ libstagefright_h264 |
|
| 950 | 951 |
libtheora |
| 951 | 952 |
libvo_aacenc |
| 952 | 953 |
libvo_amrwbenc |
| ... | ... |
@@ -1183,6 +1243,7 @@ CMDLINE_SET=" |
| 1183 | 1183 |
cc |
| 1184 | 1184 |
cpu |
| 1185 | 1185 |
cross_prefix |
| 1186 |
+ cxx |
|
| 1186 | 1187 |
dep_cc |
| 1187 | 1188 |
extra_version |
| 1188 | 1189 |
host_cc |
| ... | ... |
@@ -1208,6 +1269,7 @@ CMDLINE_SET=" |
| 1208 | 1208 |
|
| 1209 | 1209 |
CMDLINE_APPEND=" |
| 1210 | 1210 |
extra_cflags |
| 1211 |
+ extra_cxxflags |
|
| 1211 | 1212 |
" |
| 1212 | 1213 |
|
| 1213 | 1214 |
# code dependency declarations |
| ... | ... |
@@ -1430,6 +1492,7 @@ libschroedinger_decoder_deps="libschroedinger" |
| 1430 | 1430 |
libschroedinger_encoder_deps="libschroedinger" |
| 1431 | 1431 |
libspeex_decoder_deps="libspeex" |
| 1432 | 1432 |
libspeex_encoder_deps="libspeex" |
| 1433 |
+libstagefright_h264_decoder_deps="libstagefright_h264" |
|
| 1433 | 1434 |
libtheora_encoder_deps="libtheora" |
| 1434 | 1435 |
libvo_aacenc_encoder_deps="libvo_aacenc" |
| 1435 | 1436 |
libvo_amrwbenc_encoder_deps="libvo_amrwbenc" |
| ... | ... |
@@ -1651,6 +1714,7 @@ shlibdir_default="$libdir_default" |
| 1651 | 1651 |
# toolchain |
| 1652 | 1652 |
ar_default="ar" |
| 1653 | 1653 |
cc_default="gcc" |
| 1654 |
+cxx_default="g++" |
|
| 1654 | 1655 |
cc_version=\"unknown\" |
| 1655 | 1656 |
host_cc_default="gcc" |
| 1656 | 1657 |
install="install" |
| ... | ... |
@@ -1715,6 +1779,7 @@ SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)' |
| 1715 | 1715 |
|
| 1716 | 1716 |
AS_O='-o $@' |
| 1717 | 1717 |
CC_O='-o $@' |
| 1718 |
+CXX_O='-o $@' |
|
| 1718 | 1719 |
|
| 1719 | 1720 |
host_cflags='-D_ISOC99_SOURCE -O3 -g' |
| 1720 | 1721 |
host_libs='-lm' |
| ... | ... |
@@ -1867,6 +1932,7 @@ set_default arch target_os |
| 1867 | 1867 |
|
| 1868 | 1868 |
ar_default="${cross_prefix}${ar_default}"
|
| 1869 | 1869 |
cc_default="${cross_prefix}${cc_default}"
|
| 1870 |
+cxx_default="${cross_prefix}${cxx_default}"
|
|
| 1870 | 1871 |
nm_default="${cross_prefix}${nm_default}"
|
| 1871 | 1872 |
pkg_config_default="${cross_prefix}${pkg_config_default}"
|
| 1872 | 1873 |
ranlib="${cross_prefix}${ranlib}"
|
| ... | ... |
@@ -1874,7 +1940,7 @@ strip_default="${cross_prefix}${strip_default}"
|
| 1874 | 1874 |
|
| 1875 | 1875 |
sysinclude_default="${sysroot}/usr/include"
|
| 1876 | 1876 |
|
| 1877 |
-set_default cc nm pkg_config strip sysinclude |
|
| 1877 |
+set_default cc cxx nm pkg_config strip sysinclude |
|
| 1878 | 1878 |
enabled cross_compile || host_cc_default=$cc |
| 1879 | 1879 |
set_default host_cc |
| 1880 | 1880 |
|
| ... | ... |
@@ -1916,6 +1982,7 @@ tmpfile(){
|
| 1916 | 1916 |
trap 'rm -f -- $TMPFILES' EXIT |
| 1917 | 1917 |
|
| 1918 | 1918 |
tmpfile TMPC .c |
| 1919 |
+tmpfile TMPCPP .cpp |
|
| 1919 | 1920 |
tmpfile TMPE $EXESUF |
| 1920 | 1921 |
tmpfile TMPH .h |
| 1921 | 1922 |
tmpfile TMPO .o |
| ... | ... |
@@ -2133,9 +2200,11 @@ test -n "$cc_type" && enable $cc_type || |
| 2133 | 2133 |
set_default ar as dep_cc ld |
| 2134 | 2134 |
|
| 2135 | 2135 |
test -n "$CC_DEPFLAGS" || CCDEP=$DEPEND_CMD |
| 2136 |
+test -n "$CXX_DEPFLAGS" || CXXDEP=$DEPEND_CMD |
|
| 2136 | 2137 |
test -n "$AS_DEPFLAGS" || ASDEP=$DEPEND_CMD |
| 2137 | 2138 |
|
| 2138 | 2139 |
add_cflags $extra_cflags |
| 2140 |
+add_cxxflags $extra_cxxflags |
|
| 2139 | 2141 |
add_asflags $extra_cflags |
| 2140 | 2142 |
|
| 2141 | 2143 |
if test -n "$sysroot"; then |
| ... | ... |
@@ -2366,6 +2435,7 @@ if test "$?" != 0; then |
| 2366 | 2366 |
fi |
| 2367 | 2367 |
|
| 2368 | 2368 |
add_cppflags -D_ISOC99_SOURCE |
| 2369 |
+add_cxxflags -D__STDC_CONSTANT_MACROS |
|
| 2369 | 2370 |
check_cflags -std=c99 |
| 2370 | 2371 |
check_cc -D_FILE_OFFSET_BITS=64 <<EOF && add_cppflags -D_FILE_OFFSET_BITS=64 |
| 2371 | 2372 |
#include <stdlib.h> |
| ... | ... |
@@ -2663,7 +2733,7 @@ elif enabled arm; then |
| 2663 | 2663 |
elif ! check_cpp_condition stddef.h "defined __ARM_PCS || defined __SOFTFP__"; then |
| 2664 | 2664 |
case "${cross_prefix:-$cc}" in
|
| 2665 | 2665 |
*hardfloat*) enable vfp_args; fpabi=vfp ;; |
| 2666 |
- *) check_ld <<EOF && enable vfp_args && fpabi=vfp || fpabi=soft ;; |
|
| 2666 |
+ *) check_ld "cc" <<EOF && enable vfp_args && fpabi=vfp || fpabi=soft ;; |
|
| 2667 | 2667 |
__asm__ (".eabi_attribute 28, 1");
|
| 2668 | 2668 |
int main(void) { return 0; }
|
| 2669 | 2669 |
EOF |
| ... | ... |
@@ -2932,6 +3002,9 @@ enabled libopenjpeg && require libopenjpeg openjpeg.h opj_version -lopenjpeg |
| 2932 | 2932 |
enabled librtmp && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket |
| 2933 | 2933 |
enabled libschroedinger && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init |
| 2934 | 2934 |
enabled libspeex && require libspeex speex/speex.h speex_decoder_init -lspeex |
| 2935 |
+enabled libstagefright_h264 && require_cpp libstagefright_h264 "binder/ProcessState.h media/stagefright/MetaData.h |
|
| 2936 |
+ media/stagefright/MediaBufferGroup.h media/stagefright/MediaDebug.h media/stagefright/MediaDefs.h |
|
| 2937 |
+ media/stagefright/OMXClient.h media/stagefright/OMXCodec.h" android::OMXClient -lstagefright -lmedia -lutils -lbinder |
|
| 2935 | 2938 |
enabled libtheora && require libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg |
| 2936 | 2939 |
enabled libvo_aacenc && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc |
| 2937 | 2940 |
enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc |
| ... | ... |
@@ -3246,6 +3319,7 @@ echo "libopenjpeg enabled ${libopenjpeg-no}"
|
| 3246 | 3246 |
echo "librtmp enabled ${librtmp-no}"
|
| 3247 | 3247 |
echo "libschroedinger enabled ${libschroedinger-no}"
|
| 3248 | 3248 |
echo "libspeex enabled ${libspeex-no}"
|
| 3249 |
+echo "libstagefright-h264 enabled ${libstagefright_h264-no}"
|
|
| 3249 | 3250 |
echo "libtheora enabled ${libtheora-no}"
|
| 3250 | 3251 |
echo "libvo-aacenc support ${libvo_aacenc-no}"
|
| 3251 | 3252 |
echo "libvo-amrwbenc support ${libvo_amrwbenc-no}"
|
| ... | ... |
@@ -3306,6 +3380,7 @@ endif |
| 3306 | 3306 |
CC_IDENT=$cc_ident |
| 3307 | 3307 |
ARCH=$arch |
| 3308 | 3308 |
CC=$cc |
| 3309 |
+CXX=$cxx |
|
| 3309 | 3310 |
AS=$as |
| 3310 | 3311 |
LD=$ld |
| 3311 | 3312 |
DEPCC=$dep_cc |
| ... | ... |
@@ -3318,9 +3393,11 @@ LN_S=$ln_s |
| 3318 | 3318 |
STRIP=$strip |
| 3319 | 3319 |
CPPFLAGS=$CPPFLAGS |
| 3320 | 3320 |
CFLAGS=$CFLAGS |
| 3321 |
+CXXFLAGS=$CXXFLAGS |
|
| 3321 | 3322 |
ASFLAGS=$ASFLAGS |
| 3322 | 3323 |
AS_O=$CC_O |
| 3323 | 3324 |
CC_O=$CC_O |
| 3325 |
+CXX_O=$CXX_O |
|
| 3324 | 3326 |
LDFLAGS=$LDFLAGS |
| 3325 | 3327 |
FFSERVERLDFLAGS=$FFSERVERLDFLAGS |
| 3326 | 3328 |
SHFLAGS=$SHFLAGS |
| ... | ... |
@@ -3337,6 +3414,7 @@ EXESUF=$EXESUF |
| 3337 | 3337 |
EXTRA_VERSION=$extra_version |
| 3338 | 3338 |
DEPFLAGS=$DEPFLAGS |
| 3339 | 3339 |
CCDEP=$CCDEP |
| 3340 |
+CXXDEP=$CXXDEP |
|
| 3340 | 3341 |
ASDEP=$ASDEP |
| 3341 | 3342 |
CC_DEPFLAGS=$CC_DEPFLAGS |
| 3342 | 3343 |
AS_DEPFLAGS=$AS_DEPFLAGS |
| ... | ... |
@@ -594,6 +594,7 @@ OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER) += libschroedingerenc.o \ |
| 594 | 594 |
libdirac_libschro.o |
| 595 | 595 |
OBJS-$(CONFIG_LIBSPEEX_DECODER) += libspeexdec.o |
| 596 | 596 |
OBJS-$(CONFIG_LIBSPEEX_ENCODER) += libspeexenc.o |
| 597 |
+OBJS-$(CONFIG_LIBSTAGEFRIGHT_H264_DECODER)+= libstagefright.o |
|
| 597 | 598 |
OBJS-$(CONFIG_LIBTHEORA_ENCODER) += libtheoraenc.o |
| 598 | 599 |
OBJS-$(CONFIG_LIBVO_AACENC_ENCODER) += libvo-aacenc.o mpeg4audio.o |
| 599 | 600 |
OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o |
| ... | ... |
@@ -382,6 +382,7 @@ void avcodec_register_all(void) |
| 382 | 382 |
REGISTER_DECODER (LIBOPENJPEG, libopenjpeg); |
| 383 | 383 |
REGISTER_ENCDEC (LIBSCHROEDINGER, libschroedinger); |
| 384 | 384 |
REGISTER_ENCDEC (LIBSPEEX, libspeex); |
| 385 |
+ REGISTER_DECODER (LIBSTAGEFRIGHT_H264, libstagefright_h264); |
|
| 385 | 386 |
REGISTER_ENCODER (LIBTHEORA, libtheora); |
| 386 | 387 |
REGISTER_ENCODER (LIBVO_AACENC, libvo_aacenc); |
| 387 | 388 |
REGISTER_ENCODER (LIBVO_AMRWBENC, libvo_amrwbenc); |
| 388 | 389 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,516 @@ |
| 0 |
+/* |
|
| 1 |
+ * Interface to the Android Stagefright library for |
|
| 2 |
+ * H/W accelerated H.264 decoding |
|
| 3 |
+ * |
|
| 4 |
+ * Copyright (C) 2011 Mohamed Naufal |
|
| 5 |
+ * Copyright (C) 2011 Martin Storsjö |
|
| 6 |
+ * |
|
| 7 |
+ * This file is part of Libav. |
|
| 8 |
+ * |
|
| 9 |
+ * Libav is free software; you can redistribute it and/or |
|
| 10 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 11 |
+ * License as published by the Free Software Foundation; either |
|
| 12 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 13 |
+ * |
|
| 14 |
+ * Libav 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 GNU |
|
| 17 |
+ * Lesser General Public License for more details. |
|
| 18 |
+ * |
|
| 19 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 20 |
+ * License along with Libav; if not, write to the Free Software |
|
| 21 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 22 |
+ */ |
|
| 23 |
+ |
|
| 24 |
+#include <binder/ProcessState.h> |
|
| 25 |
+#include <media/stagefright/MetaData.h> |
|
| 26 |
+#include <media/stagefright/MediaBufferGroup.h> |
|
| 27 |
+#include <media/stagefright/MediaDebug.h> |
|
| 28 |
+#include <media/stagefright/MediaDefs.h> |
|
| 29 |
+#include <media/stagefright/OMXClient.h> |
|
| 30 |
+#include <media/stagefright/OMXCodec.h> |
|
| 31 |
+#include <utils/List.h> |
|
| 32 |
+#include <new> |
|
| 33 |
+ |
|
| 34 |
+extern "C" {
|
|
| 35 |
+#include "avcodec.h" |
|
| 36 |
+#include "libavutil/imgutils.h" |
|
| 37 |
+} |
|
| 38 |
+ |
|
| 39 |
+#define OMX_QCOM_COLOR_FormatYVU420SemiPlanar 0x7FA30C00 |
|
| 40 |
+ |
|
| 41 |
+using namespace android; |
|
| 42 |
+ |
|
| 43 |
+struct Frame {
|
|
| 44 |
+ status_t status; |
|
| 45 |
+ size_t size; |
|
| 46 |
+ int64_t time; |
|
| 47 |
+ int key; |
|
| 48 |
+ uint8_t *buffer; |
|
| 49 |
+ MediaBuffer* mbuffer; |
|
| 50 |
+ int32_t w, h; |
|
| 51 |
+}; |
|
| 52 |
+ |
|
| 53 |
+class CustomSource; |
|
| 54 |
+ |
|
| 55 |
+struct StagefrightContext {
|
|
| 56 |
+ AVCodecContext *avctx; |
|
| 57 |
+ AVBitStreamFilterContext *bsfc; |
|
| 58 |
+ uint8_t* orig_extradata; |
|
| 59 |
+ int orig_extradata_size; |
|
| 60 |
+ sp<MediaSource> source; |
|
| 61 |
+ List<Frame*> *in_queue, *out_queue; |
|
| 62 |
+ pthread_mutex_t in_mutex, out_mutex; |
|
| 63 |
+ pthread_cond_t condition; |
|
| 64 |
+ pthread_t decode_thread_id; |
|
| 65 |
+ |
|
| 66 |
+ Frame *end_frame; |
|
| 67 |
+ bool source_done; |
|
| 68 |
+ volatile sig_atomic_t thread_exited, stop_decode; |
|
| 69 |
+ |
|
| 70 |
+ AVFrame ret_frame; |
|
| 71 |
+ |
|
| 72 |
+ uint8_t *dummy_buf; |
|
| 73 |
+ int dummy_bufsize; |
|
| 74 |
+ |
|
| 75 |
+ OMXClient *client; |
|
| 76 |
+ sp<MediaSource> decoder; |
|
| 77 |
+ const char *decoder_component; |
|
| 78 |
+}; |
|
| 79 |
+ |
|
| 80 |
+class CustomSource : public MediaSource {
|
|
| 81 |
+public: |
|
| 82 |
+ CustomSource(AVCodecContext *avctx, sp<MetaData> meta) {
|
|
| 83 |
+ s = (StagefrightContext*)avctx->priv_data; |
|
| 84 |
+ source_meta = meta; |
|
| 85 |
+ frame_size = (avctx->width * avctx->height * 3) / 2; |
|
| 86 |
+ buf_group.add_buffer(new MediaBuffer(frame_size)); |
|
| 87 |
+ } |
|
| 88 |
+ |
|
| 89 |
+ virtual sp<MetaData> getFormat() {
|
|
| 90 |
+ return source_meta; |
|
| 91 |
+ } |
|
| 92 |
+ |
|
| 93 |
+ virtual status_t start(MetaData *params) {
|
|
| 94 |
+ return OK; |
|
| 95 |
+ } |
|
| 96 |
+ |
|
| 97 |
+ virtual status_t stop() {
|
|
| 98 |
+ return OK; |
|
| 99 |
+ } |
|
| 100 |
+ |
|
| 101 |
+ virtual status_t read(MediaBuffer **buffer, |
|
| 102 |
+ const MediaSource::ReadOptions *options) {
|
|
| 103 |
+ Frame *frame; |
|
| 104 |
+ status_t ret; |
|
| 105 |
+ |
|
| 106 |
+ pthread_mutex_lock(&s->in_mutex); |
|
| 107 |
+ |
|
| 108 |
+ while (s->in_queue->empty()) |
|
| 109 |
+ pthread_cond_wait(&s->condition, &s->in_mutex); |
|
| 110 |
+ |
|
| 111 |
+ frame = *s->in_queue->begin(); |
|
| 112 |
+ ret = frame->status; |
|
| 113 |
+ |
|
| 114 |
+ if (ret == OK) {
|
|
| 115 |
+ ret = buf_group.acquire_buffer(buffer); |
|
| 116 |
+ if (ret == OK) {
|
|
| 117 |
+ memcpy((*buffer)->data(), frame->buffer, frame->size); |
|
| 118 |
+ (*buffer)->set_range(0, frame->size); |
|
| 119 |
+ (*buffer)->meta_data()->clear(); |
|
| 120 |
+ (*buffer)->meta_data()->setInt32(kKeyIsSyncFrame,frame->key); |
|
| 121 |
+ (*buffer)->meta_data()->setInt64(kKeyTime, frame->time); |
|
| 122 |
+ } else {
|
|
| 123 |
+ av_log(s->avctx, AV_LOG_ERROR, "Failed to acquire MediaBuffer\n"); |
|
| 124 |
+ } |
|
| 125 |
+ av_freep(&frame->buffer); |
|
| 126 |
+ } |
|
| 127 |
+ |
|
| 128 |
+ s->in_queue->erase(s->in_queue->begin()); |
|
| 129 |
+ pthread_mutex_unlock(&s->in_mutex); |
|
| 130 |
+ |
|
| 131 |
+ av_freep(&frame); |
|
| 132 |
+ return ret; |
|
| 133 |
+ } |
|
| 134 |
+ |
|
| 135 |
+private: |
|
| 136 |
+ MediaBufferGroup buf_group; |
|
| 137 |
+ sp<MetaData> source_meta; |
|
| 138 |
+ StagefrightContext *s; |
|
| 139 |
+ int frame_size; |
|
| 140 |
+}; |
|
| 141 |
+ |
|
| 142 |
+void* decode_thread(void *arg) |
|
| 143 |
+{
|
|
| 144 |
+ AVCodecContext *avctx = (AVCodecContext*)arg; |
|
| 145 |
+ StagefrightContext *s = (StagefrightContext*)avctx->priv_data; |
|
| 146 |
+ Frame* frame; |
|
| 147 |
+ MediaBuffer *buffer; |
|
| 148 |
+ int decode_done = 0; |
|
| 149 |
+ do {
|
|
| 150 |
+ buffer = NULL; |
|
| 151 |
+ frame = (Frame*)av_mallocz(sizeof(Frame)); |
|
| 152 |
+ if (!frame) {
|
|
| 153 |
+ frame = s->end_frame; |
|
| 154 |
+ frame->status = AVERROR(ENOMEM); |
|
| 155 |
+ decode_done = 1; |
|
| 156 |
+ s->end_frame = NULL; |
|
| 157 |
+ } else {
|
|
| 158 |
+ frame->status = s->decoder->read(&buffer); |
|
| 159 |
+ if (frame->status == OK) {
|
|
| 160 |
+ sp<MetaData> outFormat = s->decoder->getFormat(); |
|
| 161 |
+ outFormat->findInt32(kKeyWidth , &frame->w); |
|
| 162 |
+ outFormat->findInt32(kKeyHeight, &frame->h); |
|
| 163 |
+ frame->size = buffer->range_length(); |
|
| 164 |
+ frame->mbuffer = buffer; |
|
| 165 |
+ } else if (frame->status == INFO_FORMAT_CHANGED) {
|
|
| 166 |
+ if (buffer) |
|
| 167 |
+ buffer->release(); |
|
| 168 |
+ av_free(frame); |
|
| 169 |
+ continue; |
|
| 170 |
+ } else {
|
|
| 171 |
+ decode_done = 1; |
|
| 172 |
+ } |
|
| 173 |
+ } |
|
| 174 |
+ pthread_mutex_lock(&s->out_mutex); |
|
| 175 |
+ s->out_queue->push_back(frame); |
|
| 176 |
+ pthread_mutex_unlock(&s->out_mutex); |
|
| 177 |
+ } while (!decode_done && !s->stop_decode); |
|
| 178 |
+ |
|
| 179 |
+ s->thread_exited = true; |
|
| 180 |
+ |
|
| 181 |
+ return 0; |
|
| 182 |
+} |
|
| 183 |
+ |
|
| 184 |
+static av_cold int Stagefright_init(AVCodecContext *avctx) |
|
| 185 |
+{
|
|
| 186 |
+ StagefrightContext *s = (StagefrightContext*)avctx->priv_data; |
|
| 187 |
+ sp<MetaData> meta, outFormat; |
|
| 188 |
+ int32_t colorFormat = 0; |
|
| 189 |
+ int ret; |
|
| 190 |
+ |
|
| 191 |
+ if (!avctx->extradata || !avctx->extradata_size || avctx->extradata[0] != 1) |
|
| 192 |
+ return -1; |
|
| 193 |
+ |
|
| 194 |
+ s->avctx = avctx; |
|
| 195 |
+ s->bsfc = av_bitstream_filter_init("h264_mp4toannexb");
|
|
| 196 |
+ if (!s->bsfc) {
|
|
| 197 |
+ av_log(avctx, AV_LOG_ERROR, "Cannot open the h264_mp4toannexb BSF!\n"); |
|
| 198 |
+ return -1; |
|
| 199 |
+ } |
|
| 200 |
+ |
|
| 201 |
+ s->orig_extradata_size = avctx->extradata_size; |
|
| 202 |
+ s->orig_extradata = (uint8_t*) av_mallocz(avctx->extradata_size + |
|
| 203 |
+ FF_INPUT_BUFFER_PADDING_SIZE); |
|
| 204 |
+ if (!s->orig_extradata) {
|
|
| 205 |
+ ret = AVERROR(ENOMEM); |
|
| 206 |
+ goto fail; |
|
| 207 |
+ } |
|
| 208 |
+ memcpy(s->orig_extradata, avctx->extradata, avctx->extradata_size); |
|
| 209 |
+ |
|
| 210 |
+ meta = new MetaData; |
|
| 211 |
+ if (meta == NULL) {
|
|
| 212 |
+ ret = AVERROR(ENOMEM); |
|
| 213 |
+ goto fail; |
|
| 214 |
+ } |
|
| 215 |
+ meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC); |
|
| 216 |
+ meta->setInt32(kKeyWidth, avctx->width); |
|
| 217 |
+ meta->setInt32(kKeyHeight, avctx->height); |
|
| 218 |
+ meta->setData(kKeyAVCC, kTypeAVCC, avctx->extradata, avctx->extradata_size); |
|
| 219 |
+ |
|
| 220 |
+ android::ProcessState::self()->startThreadPool(); |
|
| 221 |
+ |
|
| 222 |
+ s->source = new CustomSource(avctx, meta); |
|
| 223 |
+ s->in_queue = new List<Frame*>; |
|
| 224 |
+ s->out_queue = new List<Frame*>; |
|
| 225 |
+ s->client = new OMXClient; |
|
| 226 |
+ s->end_frame = (Frame*)av_mallocz(sizeof(Frame)); |
|
| 227 |
+ if (s->source == NULL || !s->in_queue || !s->out_queue || !s->client || |
|
| 228 |
+ !s->end_frame) {
|
|
| 229 |
+ ret = AVERROR(ENOMEM); |
|
| 230 |
+ goto fail; |
|
| 231 |
+ } |
|
| 232 |
+ |
|
| 233 |
+ if (s->client->connect() != OK) {
|
|
| 234 |
+ av_log(avctx, AV_LOG_ERROR, "Cannot connect OMX client\n"); |
|
| 235 |
+ ret = -1; |
|
| 236 |
+ goto fail; |
|
| 237 |
+ } |
|
| 238 |
+ |
|
| 239 |
+ s->decoder = OMXCodec::Create(s->client->interface(), meta, |
|
| 240 |
+ false, s->source, NULL, |
|
| 241 |
+ OMXCodec::kClientNeedsFramebuffer); |
|
| 242 |
+ if (s->decoder->start() != OK) {
|
|
| 243 |
+ av_log(avctx, AV_LOG_ERROR, "Cannot start decoder\n"); |
|
| 244 |
+ ret = -1; |
|
| 245 |
+ s->client->disconnect(); |
|
| 246 |
+ goto fail; |
|
| 247 |
+ } |
|
| 248 |
+ |
|
| 249 |
+ outFormat = s->decoder->getFormat(); |
|
| 250 |
+ outFormat->findInt32(kKeyColorFormat, &colorFormat); |
|
| 251 |
+ if (colorFormat == OMX_QCOM_COLOR_FormatYVU420SemiPlanar || |
|
| 252 |
+ colorFormat == OMX_COLOR_FormatYUV420SemiPlanar) |
|
| 253 |
+ avctx->pix_fmt = PIX_FMT_NV21; |
|
| 254 |
+ else |
|
| 255 |
+ avctx->pix_fmt = PIX_FMT_YUV420P; |
|
| 256 |
+ |
|
| 257 |
+ outFormat->findCString(kKeyDecoderComponent, &s->decoder_component); |
|
| 258 |
+ if (s->decoder_component) |
|
| 259 |
+ s->decoder_component = av_strdup(s->decoder_component); |
|
| 260 |
+ |
|
| 261 |
+ pthread_mutex_init(&s->in_mutex, NULL); |
|
| 262 |
+ pthread_mutex_init(&s->out_mutex, NULL); |
|
| 263 |
+ pthread_cond_init(&s->condition, NULL); |
|
| 264 |
+ pthread_create(&s->decode_thread_id, NULL, &decode_thread, avctx); |
|
| 265 |
+ return 0; |
|
| 266 |
+ |
|
| 267 |
+fail: |
|
| 268 |
+ av_bitstream_filter_close(s->bsfc); |
|
| 269 |
+ av_freep(&s->orig_extradata); |
|
| 270 |
+ av_freep(&s->end_frame); |
|
| 271 |
+ delete s->in_queue; |
|
| 272 |
+ delete s->out_queue; |
|
| 273 |
+ delete s->client; |
|
| 274 |
+ return ret; |
|
| 275 |
+} |
|
| 276 |
+ |
|
| 277 |
+static int Stagefright_decode_frame(AVCodecContext *avctx, void *data, |
|
| 278 |
+ int *data_size, AVPacket *avpkt) |
|
| 279 |
+{
|
|
| 280 |
+ StagefrightContext *s = (StagefrightContext*)avctx->priv_data; |
|
| 281 |
+ Frame *frame; |
|
| 282 |
+ MediaBuffer *mbuffer; |
|
| 283 |
+ status_t status; |
|
| 284 |
+ size_t size; |
|
| 285 |
+ uint8_t *buf; |
|
| 286 |
+ const uint8_t *src_data[3]; |
|
| 287 |
+ int w, h; |
|
| 288 |
+ int src_linesize[3]; |
|
| 289 |
+ int orig_size = avpkt->size; |
|
| 290 |
+ AVPacket pkt = *avpkt; |
|
| 291 |
+ int ret; |
|
| 292 |
+ |
|
| 293 |
+ if (avpkt && avpkt->data) {
|
|
| 294 |
+ av_bitstream_filter_filter(s->bsfc, avctx, NULL, &pkt.data, &pkt.size, |
|
| 295 |
+ avpkt->data, avpkt->size, avpkt->flags & AV_PKT_FLAG_KEY); |
|
| 296 |
+ avpkt = &pkt; |
|
| 297 |
+ } |
|
| 298 |
+ |
|
| 299 |
+ if (!s->source_done) {
|
|
| 300 |
+ if(!s->dummy_buf) {
|
|
| 301 |
+ s->dummy_buf = (uint8_t*)av_malloc(avpkt->size); |
|
| 302 |
+ if (!s->dummy_buf) |
|
| 303 |
+ return AVERROR(ENOMEM); |
|
| 304 |
+ s->dummy_bufsize = avpkt->size; |
|
| 305 |
+ memcpy(s->dummy_buf, avpkt->data, avpkt->size); |
|
| 306 |
+ } |
|
| 307 |
+ |
|
| 308 |
+ frame = (Frame*)av_mallocz(sizeof(Frame)); |
|
| 309 |
+ if (avpkt->data) {
|
|
| 310 |
+ frame->status = OK; |
|
| 311 |
+ frame->size = orig_size; |
|
| 312 |
+ // Stagefright can't handle negative timestamps - |
|
| 313 |
+ // if needed, work around this by offsetting them manually? |
|
| 314 |
+ if (avpkt->pts >= 0) |
|
| 315 |
+ frame->time = avpkt->pts; |
|
| 316 |
+ frame->key = avpkt->flags & AV_PKT_FLAG_KEY ? 1 : 0; |
|
| 317 |
+ frame->buffer = (uint8_t*)av_malloc(avpkt->size); |
|
| 318 |
+ if (!frame->buffer) {
|
|
| 319 |
+ av_freep(&frame); |
|
| 320 |
+ return AVERROR(ENOMEM); |
|
| 321 |
+ } |
|
| 322 |
+ uint8_t *ptr = avpkt->data; |
|
| 323 |
+ // The OMX.SEC decoder fails without this. |
|
| 324 |
+ if (avpkt->size == orig_size + avctx->extradata_size) |
|
| 325 |
+ ptr += avctx->extradata_size; |
|
| 326 |
+ memcpy(frame->buffer, ptr, orig_size); |
|
| 327 |
+ } else {
|
|
| 328 |
+ frame->status = ERROR_END_OF_STREAM; |
|
| 329 |
+ s->source_done = true; |
|
| 330 |
+ } |
|
| 331 |
+ |
|
| 332 |
+ while (true) {
|
|
| 333 |
+ if (s->thread_exited) {
|
|
| 334 |
+ s->source_done = true; |
|
| 335 |
+ break; |
|
| 336 |
+ } |
|
| 337 |
+ pthread_mutex_lock(&s->in_mutex); |
|
| 338 |
+ if (s->in_queue->size() >= 10) {
|
|
| 339 |
+ pthread_mutex_unlock(&s->in_mutex); |
|
| 340 |
+ usleep(10000); |
|
| 341 |
+ continue; |
|
| 342 |
+ } |
|
| 343 |
+ s->in_queue->push_back(frame); |
|
| 344 |
+ pthread_cond_signal(&s->condition); |
|
| 345 |
+ pthread_mutex_unlock(&s->in_mutex); |
|
| 346 |
+ break; |
|
| 347 |
+ } |
|
| 348 |
+ } |
|
| 349 |
+ while (true) {
|
|
| 350 |
+ pthread_mutex_lock(&s->out_mutex); |
|
| 351 |
+ if (!s->out_queue->empty()) break; |
|
| 352 |
+ pthread_mutex_unlock(&s->out_mutex); |
|
| 353 |
+ if (s->source_done) {
|
|
| 354 |
+ usleep(10000); |
|
| 355 |
+ continue; |
|
| 356 |
+ } else {
|
|
| 357 |
+ return orig_size; |
|
| 358 |
+ } |
|
| 359 |
+ } |
|
| 360 |
+ |
|
| 361 |
+ frame = *s->out_queue->begin(); |
|
| 362 |
+ s->out_queue->erase(s->out_queue->begin()); |
|
| 363 |
+ pthread_mutex_unlock(&s->out_mutex); |
|
| 364 |
+ |
|
| 365 |
+ mbuffer = frame->mbuffer; |
|
| 366 |
+ status = frame->status; |
|
| 367 |
+ size = frame->size; |
|
| 368 |
+ w = frame->w; |
|
| 369 |
+ h = frame->h; |
|
| 370 |
+ av_freep(&frame); |
|
| 371 |
+ |
|
| 372 |
+ if (status == ERROR_END_OF_STREAM) |
|
| 373 |
+ return 0; |
|
| 374 |
+ if (status != OK) {
|
|
| 375 |
+ if (status == AVERROR(ENOMEM)) |
|
| 376 |
+ return status; |
|
| 377 |
+ av_log(avctx, AV_LOG_ERROR, "Decode failed: %x\n", status); |
|
| 378 |
+ return -1; |
|
| 379 |
+ } |
|
| 380 |
+ |
|
| 381 |
+ // The OMX.SEC decoder doesn't signal the modified width/height |
|
| 382 |
+ if (s->decoder_component && !strncmp(s->decoder_component, "OMX.SEC", 7) && |
|
| 383 |
+ (w & 15 || h & 15)) {
|
|
| 384 |
+ if (((w + 15)&~15) * ((h + 15)&~15) * 3/2 == size) {
|
|
| 385 |
+ w = (w + 15)&~15; |
|
| 386 |
+ h = (h + 15)&~15; |
|
| 387 |
+ } |
|
| 388 |
+ } |
|
| 389 |
+ |
|
| 390 |
+ if (!avctx->width || !avctx->height || avctx->width > w || avctx->height > h) {
|
|
| 391 |
+ avctx->width = w; |
|
| 392 |
+ avctx->height = h; |
|
| 393 |
+ } |
|
| 394 |
+ |
|
| 395 |
+ ret = avctx->reget_buffer(avctx, &s->ret_frame); |
|
| 396 |
+ if (ret < 0) {
|
|
| 397 |
+ av_log(avctx, AV_LOG_ERROR, "reget buffer() failed\n"); |
|
| 398 |
+ goto end; |
|
| 399 |
+ } |
|
| 400 |
+ |
|
| 401 |
+ src_linesize[0] = w; |
|
| 402 |
+ if (avctx->pix_fmt == PIX_FMT_YUV420P) |
|
| 403 |
+ src_linesize[1] = src_linesize[2] = w/2; |
|
| 404 |
+ else if (avctx->pix_fmt == PIX_FMT_NV21) |
|
| 405 |
+ src_linesize[1] = w; |
|
| 406 |
+ |
|
| 407 |
+ buf = (uint8_t*)mbuffer->data(); |
|
| 408 |
+ src_data[0] = buf; |
|
| 409 |
+ src_data[1] = buf + src_linesize[0] * h; |
|
| 410 |
+ src_data[2] = src_data[1] + src_linesize[1] * h/2; |
|
| 411 |
+ av_image_copy(s->ret_frame.data, s->ret_frame.linesize, |
|
| 412 |
+ src_data, src_linesize, |
|
| 413 |
+ avctx->pix_fmt, avctx->width, avctx->height); |
|
| 414 |
+ |
|
| 415 |
+ *data_size = sizeof(AVFrame); |
|
| 416 |
+ *(AVFrame*)data = s->ret_frame; |
|
| 417 |
+ ret = orig_size; |
|
| 418 |
+end: |
|
| 419 |
+ mbuffer->release(); |
|
| 420 |
+ return ret; |
|
| 421 |
+} |
|
| 422 |
+ |
|
| 423 |
+static av_cold int Stagefright_close(AVCodecContext *avctx) |
|
| 424 |
+{
|
|
| 425 |
+ StagefrightContext *s = (StagefrightContext*)avctx->priv_data; |
|
| 426 |
+ Frame *frame; |
|
| 427 |
+ |
|
| 428 |
+ if (!s->thread_exited) {
|
|
| 429 |
+ s->stop_decode = 1; |
|
| 430 |
+ |
|
| 431 |
+ // Feed a dummy frame prior to signalling EOF. |
|
| 432 |
+ // This is required to terminate the decoder(OMX.SEC) |
|
| 433 |
+ // when only one frame is read during stream info detection. |
|
| 434 |
+ if (s->dummy_buf && (frame = (Frame*)av_mallocz(sizeof(Frame)))) {
|
|
| 435 |
+ frame->status = OK; |
|
| 436 |
+ frame->size = s->dummy_bufsize; |
|
| 437 |
+ frame->buffer = s->dummy_buf; |
|
| 438 |
+ pthread_mutex_lock(&s->in_mutex); |
|
| 439 |
+ s->in_queue->push_back(frame); |
|
| 440 |
+ pthread_cond_signal(&s->condition); |
|
| 441 |
+ pthread_mutex_unlock(&s->in_mutex); |
|
| 442 |
+ s->dummy_buf = NULL; |
|
| 443 |
+ } |
|
| 444 |
+ |
|
| 445 |
+ pthread_mutex_lock(&s->in_mutex); |
|
| 446 |
+ s->end_frame->status = ERROR_END_OF_STREAM; |
|
| 447 |
+ s->in_queue->push_back(s->end_frame); |
|
| 448 |
+ pthread_cond_signal(&s->condition); |
|
| 449 |
+ pthread_mutex_unlock(&s->in_mutex); |
|
| 450 |
+ s->end_frame = NULL; |
|
| 451 |
+ } |
|
| 452 |
+ |
|
| 453 |
+ pthread_join(s->decode_thread_id, NULL); |
|
| 454 |
+ |
|
| 455 |
+ if (s->ret_frame.data[0]) |
|
| 456 |
+ avctx->release_buffer(avctx, &s->ret_frame); |
|
| 457 |
+ |
|
| 458 |
+ while (!s->in_queue->empty()) {
|
|
| 459 |
+ frame = *s->in_queue->begin(); |
|
| 460 |
+ s->in_queue->erase(s->in_queue->begin()); |
|
| 461 |
+ if (frame->size) |
|
| 462 |
+ av_freep(&frame->buffer); |
|
| 463 |
+ av_freep(&frame); |
|
| 464 |
+ } |
|
| 465 |
+ |
|
| 466 |
+ while (!s->out_queue->empty()) {
|
|
| 467 |
+ frame = *s->out_queue->begin(); |
|
| 468 |
+ s->out_queue->erase(s->out_queue->begin()); |
|
| 469 |
+ if (frame->size) |
|
| 470 |
+ frame->mbuffer->release(); |
|
| 471 |
+ av_freep(&frame); |
|
| 472 |
+ } |
|
| 473 |
+ |
|
| 474 |
+ s->decoder->stop(); |
|
| 475 |
+ s->client->disconnect(); |
|
| 476 |
+ |
|
| 477 |
+ if (s->decoder_component) |
|
| 478 |
+ av_freep(&s->decoder_component); |
|
| 479 |
+ av_freep(&s->dummy_buf); |
|
| 480 |
+ av_freep(&s->end_frame); |
|
| 481 |
+ |
|
| 482 |
+ // Reset the extradata back to the original mp4 format, so that |
|
| 483 |
+ // the next invocation (both when decoding and when called from |
|
| 484 |
+ // av_find_stream_info) get the original mp4 format extradata. |
|
| 485 |
+ av_freep(&avctx->extradata); |
|
| 486 |
+ avctx->extradata = s->orig_extradata; |
|
| 487 |
+ avctx->extradata_size = s->orig_extradata_size; |
|
| 488 |
+ |
|
| 489 |
+ delete s->in_queue; |
|
| 490 |
+ delete s->out_queue; |
|
| 491 |
+ delete s->client; |
|
| 492 |
+ |
|
| 493 |
+ pthread_mutex_destroy(&s->in_mutex); |
|
| 494 |
+ pthread_mutex_destroy(&s->out_mutex); |
|
| 495 |
+ pthread_cond_destroy(&s->condition); |
|
| 496 |
+ av_bitstream_filter_close(s->bsfc); |
|
| 497 |
+ return 0; |
|
| 498 |
+} |
|
| 499 |
+ |
|
| 500 |
+AVCodec ff_libstagefright_h264_decoder = {
|
|
| 501 |
+ "libstagefright_h264", |
|
| 502 |
+ AVMEDIA_TYPE_VIDEO, |
|
| 503 |
+ CODEC_ID_H264, |
|
| 504 |
+ sizeof(StagefrightContext), |
|
| 505 |
+ Stagefright_init, |
|
| 506 |
+ NULL, //encode |
|
| 507 |
+ Stagefright_close, |
|
| 508 |
+ Stagefright_decode_frame, |
|
| 509 |
+ CODEC_CAP_DELAY, |
|
| 510 |
+ NULL, //next |
|
| 511 |
+ NULL, //flush |
|
| 512 |
+ NULL, //supported_framerates |
|
| 513 |
+ NULL, //pixel_formats |
|
| 514 |
+ NULL_IF_CONFIG_SMALL("libstagefright H.264"),
|
|
| 515 |
+}; |
| ... | ... |
@@ -21,7 +21,7 @@ |
| 21 | 21 |
#define AVCODEC_VERSION_H |
| 22 | 22 |
|
| 23 | 23 |
#define LIBAVCODEC_VERSION_MAJOR 53 |
| 24 |
-#define LIBAVCODEC_VERSION_MINOR 13 |
|
| 24 |
+#define LIBAVCODEC_VERSION_MINOR 14 |
|
| 25 | 25 |
#define LIBAVCODEC_VERSION_MICRO 0 |
| 26 | 26 |
|
| 27 | 27 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| 28 | 28 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,41 @@ |
| 0 |
+#!/bin/bash |
|
| 1 |
+ |
|
| 2 |
+if [ "$NDK" = "" ]; then |
|
| 3 |
+ echo NDK variable not set, assuming ${HOME}/android-ndk
|
|
| 4 |
+ export NDK=${HOME}/android-ndk
|
|
| 5 |
+fi |
|
| 6 |
+ |
|
| 7 |
+SYSROOT=$NDK/platforms/android-9/arch-arm |
|
| 8 |
+# Expand the prebuilt/* path into the correct one |
|
| 9 |
+TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/*-x86` |
|
| 10 |
+export PATH=$TOOLCHAIN/bin:$PATH |
|
| 11 |
+ANDROID_SOURCE=$HOME/android |
|
| 12 |
+ANDROID_LIBS=$HOME/glib |
|
| 13 |
+ |
|
| 14 |
+rm -rf ../build/libav |
|
| 15 |
+mkdir -p ../build/libav |
|
| 16 |
+ |
|
| 17 |
+DEST=../build/libav |
|
| 18 |
+FLAGS="--target-os=linux --cross-prefix=arm-linux-androideabi- --arch=arm --cpu=armv7-a" |
|
| 19 |
+FLAGS="$FLAGS --sysroot=$SYSROOT" |
|
| 20 |
+FLAGS="$FLAGS --disable-avdevice --disable-decoder=h264 --disable-decoder=h264_vdpau --enable-libstagefright-h264" |
|
| 21 |
+ |
|
| 22 |
+EXTRA_CFLAGS="-I$ANDROID_SOURCE/frameworks/base/include -I$ANDROID_SOURCE/system/core/include" |
|
| 23 |
+EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/base/media/libstagefright" |
|
| 24 |
+EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/base/include/media/stagefright/openmax" |
|
| 25 |
+EXTRA_CFLAGS="$EXTRA_CFLAGS -I$NDK/sources/cxx-stl/system/include" |
|
| 26 |
+ |
|
| 27 |
+EXTRA_CFLAGS="$EXTRA_CFLAGS -march=armv7-a -mfloat-abi=softfp -mfpu=neon" |
|
| 28 |
+EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS" |
|
| 29 |
+EXTRA_CXXFLAGS="-Wno-multichar -fno-exceptions -fno-rtti" |
|
| 30 |
+ABI="armeabi-v7a" |
|
| 31 |
+DEST="$DEST/$ABI" |
|
| 32 |
+FLAGS="$FLAGS --prefix=$DEST" |
|
| 33 |
+ |
|
| 34 |
+mkdir -p $DEST |
|
| 35 |
+ |
|
| 36 |
+echo $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS" > $DEST/info.txt |
|
| 37 |
+./configure $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS" | tee $DEST/configuration.txt |
|
| 38 |
+[ $PIPESTATUS == 0 ] || exit 1 |
|
| 39 |
+make clean |
|
| 40 |
+make -j4 || exit 1 |