Beispiel #1
0
VideoPlayer::~VideoPlayer()
{
    LOG_START();
    free(mPath);
    pthread_mutex_destroy(&mRenderMutex);
    LOG_END();
}
bool SslConnection::receive()
{
  TRACE;

  int ret = SSL_read(m_sslHandle, m_buffer, m_bufferLength);

  if ( ret > 0 ) {
    LOG_BEGIN(Logger::INFO)
      LOG_PROP("Host", m_timedTcpConnection->getHost())
      LOG_PROP("Port", m_timedTcpConnection->getPort())
      LOG_PROP("Socket", m_timedTcpConnection->getSocket())
      LOG_PROP("Bytes", ret)
    LOG_END("Received message from peer.");

    return m_message->buildMessage( (void*)m_buffer, (size_t)ret);
  }

  unsigned long sslErrNo = ERR_get_error();
  if ( ret == 0  && (sslErrNo == SSL_ERROR_ZERO_RETURN ||
                     sslErrNo == SSL_ERROR_NONE) ) {
    LOG( Logger::INFO, "SSL connection has been closed, cannot read.");
    return false;
  }

  LOG (Logger::ERR, (getSslError("The shutdown was not successful. ")
      + "system error: " + std::string(strerror(errno))).c_str() );

  return false;
}
Beispiel #3
0
void VideoPlayer::pause(bool _pause)
{
    LOG_START();
    if (mStop) {
        return;
    }
    mPause = _pause;
    LOG_END();
}
Beispiel #4
0
        A(const char *msg) : message(msg)
        {
            TRACE;

            LOG_BEGIN(Logger::DEBUG)
            LOG_PROP("message", message)
            LOG_SPROP(message)
            LOG_END("my member");
        }
Beispiel #5
0
    void testBasic()
    {
        TEST_HEADER;

        int ears(2);

        LOG_BEGIN(Logger::DEBUG)
        LOG_PROP("noses", 1)
        LOG_PROP("ears", ears)
        LOG_END("An avarege human");
    }
Beispiel #6
0
  void onMessageReady()
  {
    TRACE;

    LOG_BEGIN(Logger::INFO)
      LOG_PROP("message", m_buffer)
      LOG_PROP("host", m_connection->getHost())
      LOG_PROP("port", m_connection->getPort())
    LOG_END("Got message.");

    m_buffer.clear();
    std::unique_lock<std::mutex> lock(m_flag.m_mutex);
    m_flag.m_isReady = true;
    m_flag.m_condition_variable.notify_one();
  }
Beispiel #7
0
//static
void * VideoPlayer::doTimeCounter(void *args)
{
    LOG_START();
    VideoPlayer *player = static_cast<VideoPlayer*>(args);
    
    while(! player->mStop) {
        int base = (int)(24.0 / player->mTimeScale);
        if (player->mTimeBase % base == 0) {
            player->doUpdatePicture(player);
        }
        usleep(1000000 / 600);
        player->mTimeBase = (player->mTimeBase + 1) % 600;
    }
    
    LOG_END();
    
    return nullptr;
}
Beispiel #8
0
void VideoPlayer::stop()
{
    LOG_START();
    
    if (mStop) {
        return;
    }
    
    mStop = true;
    mPictureRingBuffer.notifyRingBufferExit();
    mPictureRingBuffer.flush();
    pthread_join(mDcoderThread, nullptr);
    pthread_join(mRenderThread, nullptr);
    
    sws_freeContext(mImageConvertCtx);
    av_frame_free(&mFrame);
    avcodec_close(mCodecCtx);
    avformat_close_input(&mFormatCtx);
    
    LOG_END();
}
Beispiel #9
0
VideoPlayer::VideoPlayer()
: mStop(true),
mPause(false),
mSeek(false),
mAccurateSeek(false),
mFormatCtx(nullptr),
mCodecCtx(nullptr),
mFrame(nullptr),
mVideoStreamIndex(-1),
mImageConvertCtx(nullptr),
mWidth(0),
mHeight(0),
mTimeScale(1.0),
mVideoEndCallback(nullptr),
mPicture(nullptr),
mTimeBase(0),
mFPS(0)
{
    LOG_START();
    pthread_mutex_init(&mRenderMutex, nullptr);
    LOG_END();
}
Beispiel #10
0
void VideoPlayer::start()
{
    LOG_START();
    
    if (! mStop) {
        return;
    }
    
    mStop = false;
    mTimeScale = 1.0;
    av_register_all();
    
    mFilePath = CCFileUtils::sharedFileUtils()->fullPathForFilename(mPath);
    vLOGE("file path: %s\n", mFilePath.c_str());
    
    if (avformat_open_input(&mFormatCtx, mFilePath.c_str(), nullptr, nullptr) != 0) {
        vLOGE("avformat_open_input failed.\n");
        return;
    }
    
    if (avformat_find_stream_info(mFormatCtx, nullptr) < 0) {
        vLOGE("avformat_find_stream_info failed.\n");
        return;
    }
    
    for (int i = 0; i < mFormatCtx->nb_streams; i ++) {
        if (mVideoStreamIndex == -1 && mFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
            mVideoStreamIndex = i;
            break;
        }
    }
    
    vLOGE("video stream index: %d\n", mVideoStreamIndex);
    
    if (mVideoStreamIndex == -1) {
        return;
    }
    
    if (mWidth <= 0) {
        mWidth = mFormatCtx->streams[mVideoStreamIndex]->codec->width;
    }
    
    if (mHeight <= 0) {
        mHeight = mFormatCtx->streams[mVideoStreamIndex]->codec->height;
    }
    
    vLOGE("width: %d height: %d\n", mWidth, mHeight);
    mCodecCtx = mFormatCtx->streams[mVideoStreamIndex]->codec;
    mCodecCtx->thread_count = 4;
    
    AVCodec *codec = avcodec_find_decoder(mCodecCtx->codec_id);
    if (codec == nullptr) {
        vLOGE("avcodec_find_decoder failed.\n");
        return;
    }
    
    if (avcodec_open2(mCodecCtx, codec, nullptr) != 0) {
        vLOGE("avcodec_open2 failed.\n");
        return;
    }
    
    if ((mFrame = av_frame_alloc()) == nullptr) {
        vLOGE("av_frame_alloc failed.\n");
    }
    
    mImageConvertCtx = sws_alloc_context();
    if (mImageConvertCtx == nullptr) {
        vLOGE("sws_alloc_context failed.\n");
        return;
    }
    sws_init_context(mImageConvertCtx, nullptr, nullptr);
    mImageConvertCtx = sws_getContext(mCodecCtx->width,
                                      mCodecCtx->height,
                                      mCodecCtx->pix_fmt,
                                      mWidth,
                                      mHeight,
                                      PIX_FMT_RGB24,
                                      SWS_FAST_BILINEAR, NULL, NULL, NULL);
    
    const CCSize& size = CCDirector::getInstance()->getWinSize();
    setPosition(Vec2(size.width, size.height));
    
    pthread_create(&mDcoderThread, nullptr, doProcessVideo, this);
    pthread_create(&mRenderThread, nullptr, doTimeCounter, this);

    LOG_END();
}
Beispiel #11
0
int main(int argc, char **argv)
{
#if defined(_WIN32) || defined(_WIN64)
    int i, invalid_arg = 0;
#else
    int loptidx, c;
#endif
    int find_emp_id = -1, find_range = -1, login_id = 702;
    int gender = GENDER_NONE;
    char passwd[MAX_LEN_PASSWD];
    int ret;

#if defined(_WIN32) || defined(_WIN64)
    /* Cannot use getopt.h on WIN32. Write a simple loop. */
    for (i = 1; i < argc; i++) {
        if (!strcmp(argv[i], "-e") || !strcmp(argv[i], "--empid")) {
            if ((i + 1) >= argc) {
                invalid_arg = 1;
                break;
            }
            find_emp_id = atoi(argv[++i]);
        } else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--range")) {
            if ((i + 1) >= argc) {
                invalid_arg = 1;
                break;
            }
            find_range = atoi(argv[++i]);
        } else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--user")) {
            if ((i + 1) >= argc) {
                invalid_arg = 1;
                break;
            }
            login_id = atoi(argv[++i]);
        } else if (!strcmp(argv[i], "-g") || !strcmp(argv[i], "--gender")) {
            if ((i + 1) >= argc) {
                invalid_arg = 1;
                break;
            }
            gender = atoi(argv[++i]);
        } else if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
            en_debug_log = 1;
        } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
            usage();
            return 0;
        }
    }

    if (invalid_arg || find_emp_id == -1) {
        printf("Invalid arguments or missing input employee id\n");
        usage();
        return 0;
    }
#else
    for (;;) {
        c = getopt_long(argc, argv, optstr, options, &loptidx);
        if (c == -1)
            break;

        switch (c) {
        case 'e':
            find_emp_id = strtoul(optarg, NULL, 10);
            break;

        case 'r':
            find_range = strtoul(optarg, NULL, 10);
            break;

        case 'u':
            login_id = strtoul(optarg, NULL, 10);
            break;

        case 'g':
            gender = strtoul(optarg, NULL, 10);
            break;

        case 'd':
            en_debug_log = 1;
            break;

        case 'h':
            usage();
            return 0;

        default:
            printf("Unknown argument: %c\n", c);
            usage();
            return 0;
        }
    }

    if (argc != optind || find_emp_id == -1) {
        printf("Invalid arguments or missing input employee id\n");
        usage();
        return 0;
    }
#endif

    LOG_BEGIN();

    LOGV("peoplefinder downloads employees' photos from the peoplefinder system\n");

    if (find_range < 0) {
        find_range = 1;
        LOGV("Find employee %05d\n", find_emp_id);
    } else {
        LOGV("Find employees %05d ~ %05d\n", find_emp_id, find_emp_id + find_range);
    }

    if (gender == GENDER_FEMALE) {
        LOGV("Find female employees only\n");
    } else if (gender == GENDER_MALE) {
        LOGV("Find male employees only\n");
    } else {
        LOGV("Find both male & female employees\n");
    }

    LOGV("Your login account: mtk%05d@DOMAIN_MTK\n", login_id);
    LOGV("Your passowrd: ");

    memset(passwd, 0, sizeof(char) * MAX_LEN_PASSWD);
    ret = input_passwd(passwd, MAX_LEN_PASSWD);
    if (ret) {
        LOGE("Fail to get the password\n");
        goto main_exit;
    }

    ret = peoplefinder(login_id, passwd, find_emp_id, find_range, gender);
    if (ret < 0) {
        LOGE("Fail to find employee(s)\n");
        goto main_exit;
    } else {
        LOGV("Find %d employee(s)\n", ret);
    }

main_exit:
    LOGV("Press any key to exit\n");
    getch();

    LOG_END();

    return ret;
}