Skip to content

Commit

Permalink
omxrtmpsrctest
Browse files Browse the repository at this point in the history
  • Loading branch information
dengxiayehu committed Jan 18, 2017
1 parent ff8ecae commit e0b1fd8
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 119 deletions.
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ SET(TARGET orps)

PROJECT(${TARGET})

SET(WEBRTC_ROOT "$ENV{WEBRTC_ROOT}")
IF("${WEBRTC_ROOT}" STREQUAL "")
MESSAGE(FATAL_ERROR "Env \"WEBRTC_ROOT\" not set.")
ENDIF()
SET(WEBRTC_OUT ${WEBRTC_ROOT}/build/out)

SET(TARGET_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
SET(SRC_DIR "${TARGET_ROOT}/src")

Expand All @@ -14,7 +20,7 @@ SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$ENV{TARGET_OUT}")
SET(CONTRIB_INCLUDE "$ENV{CONTRIB_LINUX_INSTALL_DIR}/include")
SET(CONTRIB_LIBRARY "$ENV{CONTRIB_LINUX_INSTALL_DIR}/lib")

SET(COMMON_COMPILE_FLAGS "-fstack-protector --param=ssp-buffer-size=4 -fno-strict-aliasing -Wno-unused-parameter -Wno-missing-field-initializers -pipe -fPIC -Wno-unused-local-typedefs -Wno-format -Wno-unused-result -m64 -march=x86-64 -O0 -g -funwind-tables -gsplit-dwarf -fno-exceptions -Wno-deprecated -Wno-narrowing")
SET(COMMON_COMPILE_FLAGS "-fstack-protector --param=ssp-buffer-size=4 -fno-strict-aliasing -Wno-unused-parameter -Wno-missing-field-initializers -pipe -fPIC -Wno-unused-local-typedefs -Wno-format -Wno-unused-result -m64 -march=x86-64 -O0 -g -funwind-tables -gsplit-dwarf -fno-exceptions -Wno-deprecated -std=gnu++11 -Wno-narrowing -fno-exceptions -fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -Wno-deprecated -Wno-narrowing -Wno-literal-suffix")

SET(SOURCES
src/orps.cc
Expand Down Expand Up @@ -58,8 +64,8 @@ TARGET_INCLUDE_DIRECTORIES(${TARGET} PRIVATE

########################################################################

SET(COMMON_COMPONENT_INCLUDES ${CONTRIB_INCLUDE} ${CONTRIB_INCLUDE}/bellagio ${SRC_DIR} ${SRC_DIR}/xutil .)
SET(COMMON_COMPONENT_COMPILE_DEFINITIONS "HAVE_CONFIG_H;CONFIG_DEBUG_LEVEL=255")
SET(COMMON_COMPONENT_INCLUDES ${CONTRIB_INCLUDE} ${CONTRIB_INCLUDE}/bellagio ${SRC_DIR} ${SRC_DIR}/xutil . ${WEBRTC_ROOT} ${WEBRTC_ROOT}/third_party ${WEBRTC_ROOT}/third_party/webrtc ${WEBRTC_ROOT}/webrtc)
SET(COMMON_COMPONENT_COMPILE_DEFINITIONS "HAVE_CONFIG_H;CONFIG_DEBUG_LEVEL=255;V8_DEPRECATION_WARNINGS;_FILE_OFFSET_BITS=64;CHROMIUM_BUILD;CR_CLANG_REVISION=239765-1;UI_COMPOSITOR_IMAGE_TRANSPORT;USE_AURA=1;USE_ASH=1;USE_PANGO=1;USE_CAIRO=1;USE_DEFAULT_RENDER_THEME=1;USE_LIBJPEG_TURBO=1;ENABLE_ONE_CLICK_SIGNIN;ENABLE_PRE_SYNC_BACKUP;ENABLE_REMOTING=1;ENABLE_WEBRTC=1;ENABLE_MEDIA_ROUTER=1;ENABLE_PEPPER_CDMS;ENABLE_CONFIGURATION_POLICY;ENABLE_NOTIFICATIONS;ENABLE_HIDPI=1;ENABLE_TOPCHROME_MD=1;USE_UDEV;DONT_EMBED_BUILD_METADATA;ENABLE_TASK_MANAGER=1;ENABLE_EXTENSIONS=1;ENABLE_PLUGINS=1;ENABLE_SESSION_SERVICE=1;ENABLE_AUTOFILL_DIALOG=1;ENABLE_BACKGROUND=1;CLD_VERSION=2;ENABLE_PRINTING=1;ENABLE_BASIC_PRINTING=1;ENABLE_PRINT_PREVIEW=1;ENABLE_CAPTIVE_PORTAL_DETECTION=1;ENABLE_APP_LIST=1;ENABLE_SETTINGS_APP=1;ENABLE_SUPERVISED_USERS=1;ENABLE_MDNS=1;ENABLE_SERVICE_DISCOVERY=1;V8_USE_EXTERNAL_STARTUP_DATA;FULL_SAFE_BROWSING;SAFE_BROWSING_CSD;SAFE_BROWSING_DB_LOCAL;SAFE_BROWSING_SERVICE;EXPAT_RELATIVE_PATH;WEBRTC_POSIX;WEBRTC_LINUX;WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE;USE_LIBPCI=1;USE_NSS_CERTS=1;__STDC_CONSTANT_MACROS;__STDC_FORMAT_MACROS;DYNAMIC_ANNOTATIONS_ENABLED=1;WTF_USE_DYNAMIC_ANNOTATIONS=1;_DEBUG;_GLIBCXX_DEBUG=1")
SET(COMMON_COMPONENT_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wall")

SET(LIBOMXIL_BELLAGIO_STATIC_LIBRARY "${CONTRIB_LIBRARY}/libomxil-bellagio.a")
Expand Down
21 changes: 8 additions & 13 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
#! /usr/bin/env bash
# compile.sh

ABS_DIR="$(cd "$(dirname "$0")"; pwd)"

if [ -z "$WEBRTC_ROOT" ]; then
echo "You should source envsetup.sh first."
exit 1
fi

if [ -z "$MKFLAGS" ]; then
UNAMES=$(uname -s)
MKFLAGS=
if which nproc >/dev/null; then
export MKFLAGS=-j`nproc`
elif [ "$UNAMES" == "Darwin" ] && which sysctl >/dev/null; then
export MKFLAGS=-j`sysctl -n machdep.cpu.thread_count`
fi
export MKFLAGS="$MKFLAGS VERBOSE=1"

export MKFLAGS="$MKFLAGS VERBOSE=1"
fi
CONTRIB_DIR="$ABS_DIR"/contrib
bash "$CONTRIB_DIR"/compile-contrib.sh

bash contrib/compile-contrib.sh
BUILD_DIR="$ABS_DIR"/build

[ ! -d build ] && mkdir build
cd build && cmake .. && make "$MKFLAGS"
[ ! -d "$BUILD_DIR" ] && mkdir "$BUILD_DIR"
cd "$BUILD_DIR" && cmake .. && make $MKFLAGS

$CONTRIB_LINUX_INSTALL_DIR/bin/omxregister-bellagio $CONTRIB_LINUX_INSTALL_DIR/lib/bellagio:$TARGET_OUT
2 changes: 1 addition & 1 deletion components/access/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SET_SOURCE_FILES_PROPERTIES(${SOURCES} PROPERTIES COMPILE_FLAGS "${COMMON_COMPON
ADD_LIBRARY(${TARGET} STATIC ${SOURCES})
ADD_LIBRARY(${TARGET_DYN} SHARED ${SOURCES})
ADD_DEPENDENCIES(${TARGET_DYN} xutil)
TARGET_LINK_LIBRARIES(${TARGET_DYN} -L${CONTRIB_LIBRARY} -lomxil-bellagio $ENV{TARGET_OUT}/libxutil.a ${CONTRIB_LIBRARY}/librtmp.a ${CONTRIB_LIBRARY}/libssl.a ${CONTRIB_LIBRARY}/libcrypto.a ${CONTRIB_LIBRARY}/libz.a dl rt)
TARGET_LINK_LIBRARIES(${TARGET_DYN} ${WEBRTC_OUT}/libwebrtc_common.a ${WEBRTC_OUT}/librtc_base.a ${WEBRTC_OUT}/librtc_base_approved.a ${WEBRTC_OUT}/libcrssl.a -L${CONTRIB_LIBRARY} -lomxil-bellagio $ENV{TARGET_OUT}/libxutil.a ${CONTRIB_LIBRARY}/librtmp.a ${CONTRIB_LIBRARY}/libssl.a ${CONTRIB_LIBRARY}/libcrypto.a ${CONTRIB_LIBRARY}/libz.a dl rt)

TARGET_INCLUDE_DIRECTORIES(${TARGET} PRIVATE
${COMMON_COMPONENT_INCLUDES}
Expand Down
45 changes: 26 additions & 19 deletions components/access/omx_rtmpsrc_component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
#include <omx_base_clock_port.h>
#include <omx_rtmpsrc_component.h>

#include <webrtc/base/bitbuffer.h>
#include <orps_config.h>
#include <get_bits.h>
#include <xamf.h>
#include <xmedia.h>
#include <xutil.h>
#include <xlog.h>

#define VIDEO_PORT_INDEX 0
Expand Down Expand Up @@ -144,6 +143,7 @@ OMX_ERRORTYPE omx_rtmpsrc_component_Destructor(OMX_COMPONENTTYPE *omx_comp)

SAFE_FREE(comp_priv->input_url);

SAFE_FREE(comp_priv->tmp_output_buffer->pBuffer);
SAFE_FREE(comp_priv->tmp_output_buffer);

if (comp_priv->ports) {
Expand Down Expand Up @@ -210,22 +210,24 @@ void omx_rtmpsrc_component_BufferMgmtCallback(OMX_COMPONENTTYPE *omx_comp, OMX_B
goto again;
}

xutil::GetBitContext bits;
init_get_bits(&bits, (const OMX_U8 *) packet.m_body, packet.m_nBodySize*8);
rtc::BitBuffer bitbuffer((const OMX_U8 *) packet.m_body, packet.m_nBodySize);
size_t byte_offset, bit_offset;

if (packet.m_packetType == RTMP_PACKET_TYPE_VIDEO) {
get_bits(&bits, 4); // skip frame_type
OMX_U8 codec_id = get_bits(&bits, 4);
bitbuffer.ConsumeBits(4); // skip frame_type
uint32_t codec_id;
bitbuffer.ReadBits(&codec_id, 4);
if (codec_id != 7) {
LOGE("Video codec(%d) not supported for url \"%s\"", codec_id, comp_priv->input_url);
BAIL_RETURN;
}

OMX_U8 avc_pkt_type = get_bits(&bits, 8);
get_bits(&bits, 24); // skip composition_time
OMX_U32 data_offset = (4 + 4 + 8 + 24)/8;
const OMX_U8 *data = (const OMX_U8 *) packet.m_body + data_offset;
OMX_U32 data_size = packet.m_nBodySize - data_offset;
OMX_U8 avc_pkt_type;
bitbuffer.ReadUInt8(&avc_pkt_type);
bitbuffer.ConsumeBits(24); // skip composition_time
bitbuffer.GetCurrentOffset(&byte_offset, &bit_offset);
const OMX_U8 *data = (const OMX_U8 *) packet.m_body + byte_offset;
OMX_U32 data_size = packet.m_nBodySize - byte_offset;

if (output_buffer->nOutputPortIndex == VIDEO_PORT_INDEX) {
dst_buffer = output_buffer;
Expand Down Expand Up @@ -258,21 +260,26 @@ void omx_rtmpsrc_component_BufferMgmtCallback(OMX_COMPONENTTYPE *omx_comp, OMX_B
BAIL_RETURN;
}
} else if (packet.m_packetType == RTMP_PACKET_TYPE_AUDIO) {
OMX_U8 sound_format = get_bits(&bits, 4);
OMX_U8 sound_rate = get_bits(&bits, 2);
OMX_U8 sound_size = get_bits(&bits, 1);
OMX_U8 sound_type = get_bits(&bits, 1);
uint32_t sound_format;
bitbuffer.ReadBits(&sound_format, 4);
uint32_t sound_rate;
bitbuffer.ReadBits(&sound_rate, 2);
uint32_t sound_size;
bitbuffer.ReadBits(&sound_size, 1);
uint32_t sound_type;
bitbuffer.ReadBits(&sound_type, 1);

if (sound_format != 10 || sound_rate != 3 || sound_size != 1 || sound_type != 1) {
LOGE("Unsupported audio paket(sound_format=%d sound_rate=%d sound_size=%d sound_type=%d) for url \"%s\"",
sound_format, sound_rate, sound_size, sound_type, comp_priv->input_url);
BAIL_RETURN;
}

OMX_U8 aac_packet_type = get_bits(&bits, 8);
OMX_U32 data_offset = (4 + 2 + 1 + 1 + 8)/8;
const OMX_U8 *data = (const OMX_U8 *) packet.m_body + data_offset;
OMX_U32 data_size = packet.m_nBodySize - data_offset;
uint8_t aac_packet_type;
bitbuffer.ReadUInt8(&aac_packet_type);
bitbuffer.GetCurrentOffset(&byte_offset, &bit_offset);
const OMX_U8 *data = (const OMX_U8 *) packet.m_body + byte_offset;
OMX_U32 data_size = packet.m_nBodySize - byte_offset;

if (output_buffer->nOutputPortIndex == AUDIO_PORT_INDEX) {
dst_buffer = output_buffer;
Expand Down
7 changes: 4 additions & 3 deletions contrib/compile-contrib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ function compile_libomxil_bellagio() {
export LD_LIBRARY_PATH=$CONTRIB_LINUX_INSTALL_DIR/lib:$LD_LIBRARY_PATH
export BELLAGIO_SEARCH_PATH=$CONTRIB_LINUX_INSTALL_DIR/lib/bellagio/:$CONTRIB_LINUX_INSTALL_DIR/lib/extern_omxcomp/lib/:$CONTRIB_LINUX_INSTALL_DIR/lib/
export PKG_CONFIG_PATH=$CONTRIB_LINUX_INSTALL_DIR/lib/pkgconfig/:/usr/local/lib/pkgconfig/:/usr/lib/pkgconfig/:$PKG_CONFIG_PATH
local _cflags="-g -O0 -Wno-error=switch"
autoreconf -i -f . &&
./configure --enable-debug --prefix="$CONTRIB_LINUX_INSTALL_DIR" &&
make CFLAGS="-g -O0 -Wno-error=switch" &&
make install &&
make check && return 0
make CFLAGS="$_cflags" &&
make CFLAGS="$_cflags" check &&
make CFLAGS="$_cflags" install && return 0
return 1
}

Expand Down
Binary file modified contrib/tarballs/libomxil-bellagio-0.9.3.tgz
Binary file not shown.
3 changes: 0 additions & 3 deletions contrib/webrtc/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 2.6)

SET(WEBRTC_ROOT "$ENV{WEBRTC_ROOT}")
IF("${WEBRTC_ROOT}" STREQUAL "")
MESSAGE(FATAL_ERROR "Env \"WEBRTC_ROOT\" not set.")
ENDIF()

SET(OUT ${PROJECT_BINARY_DIR}/out)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUT})
Expand Down
12 changes: 7 additions & 5 deletions src/xutil/xmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
#define _XMACROS_H_

#ifndef SAFE_DELETE
# define SAFE_DELETE(p) do { \
#define SAFE_DELETE(p) do { \
delete p; \
p = NULL; \
} while (0)
#endif
#ifndef SAFE_DELETE_ARRAY
# define SAFE_DELETE_ARRAY(p) do { \
#define SAFE_DELETE_ARRAY(p) do { \
delete [] p; \
p = NULL; \
} while (0)
# define SAFE_DELETEA SAFE_DELETE_ARRAY
#endif

#ifndef SAFE_FREE
# define SAFE_FREE(p) do { \
#define SAFE_FREE(p) do { \
free(p); \
p = NULL; \
} while (0)
#endif

#ifndef SAFE_CLOSE
# define SAFE_CLOSE(fd) do { \
#define SAFE_CLOSE(fd) do { \
if (fd >= 0) { \
::close(fd); \
fd = -1; \
Expand All @@ -45,9 +45,11 @@
if (expr) { cmd; goto label; } \
} while (0)

#ifndef DISALLOW_COPY_AND_ASSIGN
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName &); \
void operator=(const TypeName &)
void operator=(const TypeName &)
#endif

#include <sys/syscall.h>
#define gettid() syscall(__NR_gettid)
Expand Down
7 changes: 5 additions & 2 deletions test/components/rtmpsrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ SET(SOURCES
SET_SOURCE_FILES_PROPERTIES(${SOURCES} PROPERTIES COMPILE_FLAGS "${COMMON_COMPONENT_COMPILE_FLAGS}")

ADD_EXECUTABLE(${TARGET} ${SOURCES})
TARGET_LINK_LIBRARIES(${TARGET} ${LIBOMXIL_BELLAGIO_STATIC_LIBRARY} $ENV{TARGET_OUT}/libxutil.a pthread dl)
ADD_DEPENDENCIES(${TARGET} xutil)
TARGET_LINK_LIBRARIES(${TARGET} ${WEBRTC_OUT}/libwebrtc_common.a ${WEBRTC_OUT}/librtc_base.a ${WEBRTC_OUT}/librtc_base_approved.a ${WEBRTC_OUT}/libcrssl.a ${LIBOMXIL_BELLAGIO_STATIC_LIBRARY} $ENV{TARGET_OUT}/libxutil.a pthread dl)

TARGET_INCLUDE_DIRECTORIES(${TARGET} PRIVATE
${COMMON_COMPONENT_INCLUDES}
)

SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_DEFINITIONS "${COMMON_COMPONENT_COMPILE_DEFINITIONS}")
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_DEFINITIONS "${COMMON_COMPONENT_COMPILE_DEFINITIONS};")

SET_TARGET_PROPERTIES(${TARGET} PROPERTIES LINK_FLAGS "-Wl,-z,now -Wl,-z,relro -Wl,--fatal-warnings -Wl,-z,defs -pthread -Wl,-z,noexecstack -fPIC -fuse-ld=gold -Wl,--disable-new-dtags -m64 -Wl,--detect-odr-violations -Wl,--icf=all")
Loading

0 comments on commit e0b1fd8

Please sign in to comment.