diff --git a/apollo.sh b/apollo.sh index 640ff91993f69c43852dd8b91a3b0c2b730560cc..3a2ddbf494102b349a616e54b92be747b6a22c45 100755 --- a/apollo.sh +++ b/apollo.sh @@ -94,6 +94,12 @@ function check_esd_files() { function generate_build_targets() { COMMON_TARGETS="//cyber/... union //modules/common/kv_db/... union //modules/dreamview/..." case $BUILD_FILTER in + cyber) + BUILD_TARGETS=`bazel query //cyber/...` + ;; + drivers) + BUILD_TARGETS=`bazel query //cyber/... union //modules/drivers/... except //modules/drivers/tools/... except //modules/drivers/canbus/... except //modules/drivers/video/...` + ;; control) BUILD_TARGETS=`bazel query $COMMON_TARGETS union //modules/control/... ` ;; @@ -156,10 +162,18 @@ function build() { build_py_proto # Clear KV DB and update commit_id after compiling. - rm -fr data/kv_db* - REVISION=$(get_revision) - ./bazel-bin/modules/common/kv_db/kv_db_tool --op=put \ - --key="apollo:data:commit_id" --value="$REVISION" + if [ "$BUILD_FILTER" == 'cyber' ] || [ "$BUILD_FILTER" == 'drivers' ]; then + info "Skipping revision recording" + else + bazel build $JOB_ARG $DEFINES -c $@ $BUILD_TARGETS + if [ ${PIPESTATUS[0]} -ne 0 ]; then + fail 'Build failed!' + fi + rm -fr data/kv_db* + REVISION=$(get_revision) + ./bazel-bin/modules/common/kv_db/kv_db_tool --op=put \ + --key="apollo:data:commit_id" --value="$REVISION" + fi if [ -d /apollo-simulator ] && [ -e /apollo-simulator/build.sh ]; then cd /apollo-simulator && bash build.sh build @@ -671,6 +685,8 @@ function print_usage() { ${BLUE}build_gpu${NONE}: run build only with Caffe GPU mode support ${BLUE}build_opt_gpu${NONE}: build optimized binary with Caffe GPU mode support ${BLUE}build_fe${NONE}: compile frontend javascript code, this requires all the node_modules to be installed already + ${BLUE}build_cyber [dbg|opt]${NONE}: build Cyber RT only + ${BLUE}build_drivers [dbg|opt]${NONE}: build drivers only ${BLUE}build_planning${NONE}: compile planning and its dependencies. ${BLUE}build_control${NONE}: compile control and its dependencies. ${BLUE}build_prediction${NONE}: compile prediction and its dependencies. @@ -737,6 +753,26 @@ function main() { apollo_build_dbg $@ fi ;; + build_cyber) + BUILD_FILTER="cyber" + if [ "$1" == "opt" ]; then + shift + apollo_build_opt $@ + else + shift + apollo_build_dbg $@ + fi + ;; + build_drivers) + BUILD_FILTER="drivers" + if [ "$1" == "opt" ]; then + shift + apollo_build_opt $@ + else + shift + apollo_build_dbg $@ + fi + ;; build_control) BUILD_FILTER="control" apollo_build_dbg $@ diff --git a/docker/scripts/cyber_into.sh b/docker/scripts/cyber_into.sh new file mode 100755 index 0000000000000000000000000000000000000000..78282044764c6f7f8b29be4df210566633b74569 --- /dev/null +++ b/docker/scripts/cyber_into.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +############################################################################### +# Copyright 2017 The Apollo Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################### + +xhost +local:root 1>/dev/null 2>&1 +docker exec \ + -u $USER \ + -it apollo_cyber_$USER \ + /bin/bash +xhost -local:root 1>/dev/null 2>&1 diff --git a/docker/scripts/cyber_start.sh b/docker/scripts/cyber_start.sh new file mode 100755 index 0000000000000000000000000000000000000000..7839fba8f0eec871fe0f9ee21b49c06d88fc5e8f --- /dev/null +++ b/docker/scripts/cyber_start.sh @@ -0,0 +1,277 @@ +#!/usr/bin/env bash + +############################################################################### +# Copyright 2017 The Apollo Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################### + +INCHINA="no" +LOCAL_IMAGE="no" +VERSION="" +ARCH=$(uname -m) +VERSION_X86_64="dev-x86_64-18.04-20190514_1036" +VERSION_AARCH64="" +VERSION_OPT="" + +# Check whether user has agreed license agreement +function check_agreement() { + agreement_record="${HOME}/.apollo_agreement.txt" + if [ -e "$agreement_record" ]; then + return + fi + + AGREEMENT_FILE="$APOLLO_ROOT_DIR/scripts/AGREEMENT.txt" + if [ ! -e "$AGREEMENT_FILE" ]; then + error "AGREEMENT $AGREEMENT_FILE does not exist." + exit 1 + fi + + cat $AGREEMENT_FILE + tip="Type 'y' or 'Y' to agree to the license agreement above, or type any other key to exit" + echo $tip + read -n 1 user_agreed + if [ "$user_agreed" == "y" ] || [ "$user_agreed" == "Y" ]; then + cp $AGREEMENT_FILE $agreement_record + echo "$tip" >> $agreement_record + echo "$user_agreed" >> $agreement_record + else + exit 1 + fi +} + +function check_host_environment() { + echo 'Host evvironment checking done.' +} + +function show_usage() +{ +cat < Specify which version of a docker image to pull. + -l, --local Use local docker image. + stop Stop all running Apollo containers. +EOF +exit 0 +} + +function stop_containers() +{ +running_containers=$(docker ps --format "{{.Names}}") + +for i in ${running_containers[*]} +do + if [[ "$i" =~ apollo_* ]];then + printf %-*s 70 "stopping container: $i ..." + docker stop $i > /dev/null + if [ $? -eq 0 ];then + printf "\033[32m[DONE]\033[0m\n" + else + printf "\033[31m[FAILED]\033[0m\n" + fi + fi +done +} + +APOLLO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )" + +if [ ! -e /apollo ]; then + sudo ln -sf ${APOLLO_ROOT_DIR} /apollo +fi + +if [ -e /proc/sys/kernel ]; then + echo "/apollo/data/core/core_%e.%p" | sudo tee /proc/sys/kernel/core_pattern > /dev/null +fi + +source ${APOLLO_ROOT_DIR}/scripts/apollo_base.sh +check_agreement +check_host_environment + +while [ $# -gt 0 ] +do + case "$1" in + -C|--docker-cn-mirror) + INCHINA="yes" + ;; + -t|--tag) + VAR=$1 + [ -z $VERSION_OPT ] || echo -e "\033[093mWarning\033[0m: mixed option $VAR with $VERSION_OPT, only the last one will take effect.\n" + shift + VERSION_OPT=$1 + [ -z ${VERSION_OPT// /} ] && echo -e "Missing parameter for $VAR" && exit 2 + [[ $VERSION_OPT =~ ^-.* ]] && echo -e "Missing parameter for $VAR" && exit 2 + ;; + -h|--help) + show_usage + ;; + -l|--local) + LOCAL_IMAGE="yes" + ;; + stop) + stop_containers + exit 0 + ;; + *) + echo -e "\033[93mWarning\033[0m: Unknown option: $1" + exit 2 + ;; + esac + shift +done + +if [ ! -z "$VERSION_OPT" ]; then + VERSION=$VERSION_OPT +elif [ ${ARCH} == "x86_64" ]; then + VERSION=${VERSION_X86_64} +elif [ ${ARCH} == "aarch64" ]; then + VERSION=${VERSION_AARCH64} +else + echo "Unknown architecture: ${ARCH}" + exit 0 +fi + +if [ -z "${DOCKER_REPO}" ]; then + DOCKER_REPO=apolloauto/apollo +fi + +if [ "$INCHINA" == "yes" ]; then + DOCKER_REPO=registry.docker-cn.com/apolloauto/apollo +fi + +if [ "$LOCAL_IMAGE" == "yes" ] && [ -z "$VERSION_OPT" ]; then + VERSION="local_dev" +fi + + +IMG=${DOCKER_REPO}:$VERSION + +function local_volumes() { + # Apollo root and bazel cache dirs are required. + volumes="-v $APOLLO_ROOT_DIR:/apollo \ + -v $HOME/.cache:${DOCKER_HOME}/.cache" + case "$(uname -s)" in + Linux) + case "$(lsb_release -r | cut -f2)" in + 14.04) + volumes="${volumes} " + ;; + *) + volumes="${volumes} -v /dev:/dev " + ;; + esac + volumes="${volumes} -v /media:/media \ + -v /tmp/.X11-unix:/tmp/.X11-unix:rw \ + -v /etc/localtime:/etc/localtime:ro \ + -v /usr/src:/usr/src \ + -v /lib/modules:/lib/modules" + ;; + Darwin) + # MacOS has strict limitations on mapping volumes. + chmod -R a+wr ~/.cache/bazel + ;; + esac + echo "${volumes}" +} + +function main(){ + + if [ "$LOCAL_IMAGE" = "yes" ];then + info "Start docker container based on local image : $IMG" + else + info "Start pulling docker image $IMG ..." + docker pull $IMG + if [ $? -ne 0 ];then + error "Failed to pull docker image." + exit 1 + fi + fi + + APOLLO_CYBER="apollo_cyber_${USER}" + docker ps -a --format "{{.Names}}" | grep "$APOLLO_CYBER" 1>/dev/null + if [ $? == 0 ]; then + docker stop $APOLLO_CYBER 1>/dev/null + docker rm -v -f $APOLLO_CYBER 1>/dev/null + fi + + local display="" + if [[ -z ${DISPLAY} ]];then + display=":0" + else + display="${DISPLAY}" + fi + + setup_device + + USER_ID=$(id -u) + GRP=$(id -g -n) + GRP_ID=$(id -g) + LOCAL_HOST=`hostname` + DOCKER_HOME="/home/$USER" + if [ "$USER" == "root" ];then + DOCKER_HOME="/root" + fi + if [ ! -d "$HOME/.cache" ];then + mkdir "$HOME/.cache" + fi + + info "Starting docker container \"${APOLLO_CYBER}\" ..." + + DOCKER_CMD="nvidia-docker" + USE_GPU=1 + if ! [ -x "$(command -v ${DOCKER_CMD})" ]; then + DOCKER_CMD="docker" + USE_GPU=0 + fi + + ${DOCKER_CMD} run -it \ + -d \ + --privileged \ + --name $APOLLO_CYBER \ + -e DISPLAY=$display \ + -e DOCKER_USER=$USER \ + -e USER=$USER \ + -e DOCKER_USER_ID=$USER_ID \ + -e DOCKER_GRP="$GRP" \ + -e DOCKER_GRP_ID=$GRP_ID \ + -e DOCKER_IMG=$IMG \ + -e USE_GPU=$USE_GPU \ + -e OMP_NUM_THREADS=1 \ + $(local_volumes) \ + --net host \ + -w /apollo \ + --add-host in_cyber_docker:127.0.0.1 \ + --add-host ${LOCAL_HOST}:127.0.0.1 \ + --hostname in_cyber_docker \ + --shm-size 2G \ + --pid=host \ + -v /dev/null:/dev/raw1394 \ + $IMG \ + /bin/bash + + if [ $? -ne 0 ];then + error "Failed to start docker container \"${APOLLO_CYBER}\" based on image: $IMG" + exit 1 + fi + + if [ "${USER}" != "root" ]; then + docker exec $APOLLO_CYBER bash -c '/apollo/scripts/docker_adduser.sh' + fi + + ok "Finished setting up Apollo docker environment. Now you can enter with: \nbash docker/scripts/cyber_into.sh" + ok "Enjoy!" +} + +main diff --git a/modules/drivers/camera/usb_cam.cc b/modules/drivers/camera/usb_cam.cc index 3d8a76172b94582eb44982bedc2e88c18026d075..c211197f05ef5382b87419f3dee36dd2f47bab20 100644 --- a/modules/drivers/camera/usb_cam.cc +++ b/modules/drivers/camera/usb_cam.cc @@ -107,25 +107,45 @@ int UsbCam::init_mjpeg_decoder(int image_width, int image_height) { } avcodec_context_ = avcodec_alloc_context3(avcodec_); + +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 0, 0) + avframe_camera_ = av_frame_alloc(); + avframe_rgb_ = av_frame_alloc(); + + avpicture_alloc(reinterpret_cast(avframe_rgb_), AV_PIX_FMT_RGB24, + image_width, image_height); +#else avframe_camera_ = avcodec_alloc_frame(); avframe_rgb_ = avcodec_alloc_frame(); avpicture_alloc(reinterpret_cast(avframe_rgb_), PIX_FMT_RGB24, image_width, image_height); +#endif avcodec_context_->codec_id = AV_CODEC_ID_MJPEG; avcodec_context_->width = image_width; avcodec_context_->height = image_height; #if LIBAVCODEC_VERSION_MAJOR > 52 +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 0, 0) + avcodec_context_->pix_fmt = AV_PIX_FMT_YUV422P; +#else avcodec_context_->pix_fmt = PIX_FMT_YUV422P; +#endif avcodec_context_->codec_type = AVMEDIA_TYPE_VIDEO; #endif +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 0, 0) + avframe_camera_size_ = + avpicture_get_size(AV_PIX_FMT_YUV422P, image_width, image_height); + avframe_rgb_size_ = + avpicture_get_size(AV_PIX_FMT_RGB24, image_width, image_height); +#else avframe_camera_size_ = avpicture_get_size(PIX_FMT_YUV422P, image_width, image_height); avframe_rgb_size_ = avpicture_get_size(PIX_FMT_RGB24, image_width, image_height); +#endif /* open it */ if (avcodec_open2(avcodec_context_, avcodec_, &avoptions_) < 0) { @@ -175,16 +195,30 @@ void UsbCam::mjpeg2rgb(char* mjpeg_buffer, int len, char* rgb_buffer, return; } +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 0, 0) + video_sws_ = + sws_getContext(xsize, ysize, avcodec_context_->pix_fmt, xsize, ysize, + AV_PIX_FMT_RGB24, SWS_BILINEAR, nullptr, nullptr, nullptr); +#else video_sws_ = sws_getContext(xsize, ysize, avcodec_context_->pix_fmt, xsize, ysize, PIX_FMT_RGB24, SWS_BILINEAR, nullptr, nullptr, nullptr); +#endif + sws_scale(video_sws_, avframe_camera_->data, avframe_camera_->linesize, 0, ysize, avframe_rgb_->data, avframe_rgb_->linesize); sws_freeContext(video_sws_); +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 0, 0) + int size = avpicture_layout( + reinterpret_cast(avframe_rgb_), AV_PIX_FMT_RGB24, + xsize, ysize, + reinterpret_cast(rgb_buffer), avframe_rgb_size_); +#else int size = avpicture_layout( reinterpret_cast(avframe_rgb_), PIX_FMT_RGB24, xsize, ysize, reinterpret_cast(rgb_buffer), avframe_rgb_size_); +#endif if (size != avframe_rgb_size_) { AERROR << "webcam: avpicture_layout error: " << size; return; diff --git a/scripts/docker_adduser.sh b/scripts/docker_adduser.sh index cb295b70793ef453922bc33a325039d84f67cbbd..8bc9617ed6a51901763bb0ac8b93fc1fd4fa6064 100755 --- a/scripts/docker_adduser.sh +++ b/scripts/docker_adduser.sh @@ -63,12 +63,3 @@ fi if [ -e /dev/camera/trafficlights ]; then chmod a+rw /dev/camera/trafficlights fi - - -if [ "$RELEASE_DOCKER" != "1" ];then - # setup ros package - # this is a temporary solution to avoid ros package downloading. - ROS="/home/tmp/ros" - chmod a+w "${ROS}/share/velodyne/launch/start_velodyne.launch" - chmod a+w -R "${ROS}/share/velodyne_pointcloud/params" -fi