Exemplo n.º 1
0
//进度回调函数
static void 
xmt_download_pos_callback(long handle, long total_size, 
        long download_size, long int user)
{//show_debug("----------------->%d:%d\n", total_size, download_size);
    stream_info_t *strm_info;
    xmt_rec_strm_t *rec_strm;

    NMP_ASSERT(XMT_INVALID_HANDLE != handle);
    NMP_ASSERT(user);

    strm_info = (stream_info_t*)user;
    rec_strm = (xmt_rec_strm_t*)user;

    if (strm_info->opened && rec_strm->enable)
    {
        if (-1 == (int)download_size)
        {
            show_info("----------------->The end frame! total_size: %d\n", 
                (int)total_size);
            write_stream_data((gpointer)strm_info->opened, 
                (gulong)0, (gulong)0, (guint8*)NULL, (gsize)0, 
                (guint8)15, (guint8*)NULL, (gsize)0, (guint8)0);
        }
    }
}
Exemplo n.º 2
0
static int write_header(AVFormatContext *s)
{
    AVIOContext *pb = s->pb;
    WtvContext *wctx = s->priv_data;
    int i, pad, ret;
    AVStream *st;

    wctx->last_chunk_pos     = -1;
    wctx->last_timestamp_pos = -1;

    ff_put_guid(pb, &ff_wtv_guid);
    ff_put_guid(pb, &sub_wtv_guid);

    avio_wl32(pb, 0x01);
    avio_wl32(pb, 0x02);
    avio_wl32(pb, 1 << WTV_SECTOR_BITS);
    avio_wl32(pb, 1 << WTV_BIGSECTOR_BITS);

    //write initial root fields
    avio_wl32(pb, 0); // root_size, update later
    write_pad(pb, 4);
    avio_wl32(pb, 0); // root_sector, update it later.

    write_pad(pb, 32);
    avio_wl32(pb, 0); // file ends pointer, update it later.

    pad = (1 << WTV_SECTOR_BITS) - avio_tell(pb);
    write_pad(pb, pad);

    wctx->timeline_start_pos = avio_tell(pb);

    wctx->serial = 1;
    wctx->last_chunk_pos = -1;
    wctx->first_video_flag = 1;

    for (i = 0; i < s->nb_streams; i++) {
        st = s->streams[i];
        ret = write_stream_codec(s, st);
        if (ret < 0) {
            av_log(s, AV_LOG_ERROR, "write stream codec failed codec_type(0x%x)\n", st->codec->codec_type);
            return -1;
        }
        if (!i)
            write_sync(s);
    }

    for (i = 0; i < s->nb_streams; i++) {
        st = s->streams[i];
        ret  = write_stream_data(s, st);
        if (ret < 0) {
            av_log(s, AV_LOG_ERROR, "write stream data failed codec_type(0x%x)\n", st->codec->codec_type);
            return -1;
        }
    }

    if (wctx->nb_index)
        write_index(s);

    return 0;
}
Exemplo n.º 3
0
static int 
hie_record_data_callback(HSTREAM handle, const StreamMediaFrame *strm_data, 
    DWORD user_data)
{
    stream_info_t *strm_info;
    hie_rec_strm_t *rec_strm;

    NMP_ASSERT(HIE_INVALID_HANDLE != handle);
    NMP_ASSERT(strm_data);
    NMP_ASSERT(user_data);

    strm_info = (stream_info_t*)user_data;
    rec_strm  = (hie_rec_strm_t*)strm_info;

    if (eFrameSysHeader == strm_data->dwFrameType)
    {
        if (!strm_info->opened && !strm_info->media_size)
        {
            memcpy(strm_info->media_info, strm_data->cFrameBuffer.pBuffer, 
                strm_data->cFrameBuffer.dwBufLen);
            strm_info->media_size = strm_data->cFrameBuffer.dwBufLen;
        }
    }
    else
    {
        if (!strm_data->cFrameBuffer.pBuffer)
            return 0;

        while (1)
        {
            if (strm_info->opened && rec_strm->enable)
            {
                if (!test_stream_blockable((gpointer)strm_info->opened, 
                        (gsize)strm_data->cFrameBuffer.dwBufLen))
                {//printf("----------->%d\n", (int)strm_data->dwDataSize);
                    show_debug("channel: %d, len: %d\n", strm_info->channel, 
                        (int)strm_data->cFrameBuffer.dwBufLen);
                    write_stream_data((gpointer)strm_info->opened, 
                        (gulong)strm_info->ts, (gulong)DEF_TIMESTAMP, 
                        (guint8*)strm_data->cFrameBuffer.pBuffer, 
                        (gsize)strm_data->cFrameBuffer.dwBufLen, 
                        (guint8)strm_data->dwFrameType, (guint8*)NULL, 
                        (gsize)0, (guint8)0);
                    break;
                }
                else
                {
                    show_debug("Sleep some times.\n");
                    usleep(RECORD_PACKET_SLEEP_TIME);
                }
            }
            else
                break;
        }
    }

    return 0;
}
Exemplo n.º 4
0
static int 
xmt_record_data_callback(long handle, long data_type, 
        unsigned char *buffer, long buf_size, long user)
{//show_debug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<%d:%d\n", data_type, buf_size);
    int flag = 0;
    stream_info_t *strm_info;
    xmt_rec_strm_t *rec_strm;

    NMP_ASSERT(XMT_INVALID_HANDLE != handle);
    NMP_ASSERT(buffer && 0 < buf_size);
    NMP_ASSERT(user);

    strm_info = (stream_info_t*)user;
    rec_strm  = (xmt_rec_strm_t*)strm_info;

    switch (data_type)
    {
        case 0:
            if (strm_info->opened && rec_strm->enable)
            {
                if (!test_stream_blockable((gpointer)strm_info->opened, 
                    (gsize)buf_size))
                {
                    flag = 1;
                    write_stream_data((gpointer)strm_info->opened, 
                        (gulong)0, (gulong)0, (guint8*)buffer, (gsize)buf_size, 
                        (guint8)1, (guint8*)NULL, (gsize)0, (guint8)0);
                }
                else
                {
                    //show_debug("Sleep some times.\n");
                    usleep(RECORD_PACKET_SLEEP_TIME);
                }
            }
            break;

        default:
            break;
    }

    return flag;
}
Exemplo n.º 5
0
static int 
hie_real_data_callback(HSTREAM handle, const StreamMediaFrame *strm_data, 
    DWORD user_data)
{
    stream_info_t *strm_info;
    NMP_ASSERT(HIE_INVALID_HANDLE != handle);
    NMP_ASSERT(user_data);

    strm_info = (stream_info_t*)user_data;

    if (eFrameSysHeader == strm_data->dwFrameType)
    {
        if (!strm_info->media_info)
        {
            memcpy(strm_info->media_info, strm_data->cFrameBuffer.pBuffer, 
                strm_data->cFrameBuffer.dwBufLen);
            strm_info->media_size = strm_data->cFrameBuffer.dwBufLen;
        }
        return 0;
    }
    else
    {
        if (strm_info->opened)
        {
            show_debug("channel: %d, len: %d\n", strm_info->channel, 
                (int)strm_data->cFrameBuffer.dwBufLen);
            write_stream_data((gpointer)strm_info->opened, 
                (gulong)strm_info->ts, (gulong)DEF_TIMESTAMP, 
                (guint8*)strm_data->cFrameBuffer.pBuffer, 
                (gsize)strm_data->cFrameBuffer.dwBufLen, 
                (guint8)strm_data->dwFrameType, (guint8*)NULL, 
                (gsize)0, (guint8)0);
        }
    }

    return 0;
}
Exemplo n.º 6
0
static int 
xmt_real_data_callback(long handle, long data_type, 
        unsigned char *buffer, long buf_size, long user)
{//show_debug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<%d:%d\n", data_type, buf_size);
    struct timeval ts;
    stream_info_t *strm_info;

    NMP_ASSERT(XMT_INVALID_HANDLE != handle);
    NMP_ASSERT(buffer && 0 < buf_size);
    NMP_ASSERT(user);

    strm_info = (stream_info_t*)user;
    switch (data_type)
    {
        case 0:
        default://帧数据
            if (strm_info->opened)
            {
                if (0 == strm_info->ts)
                {
                    gettimeofday(&ts, NULL);
                    strm_info->ts = ts.tv_sec*1000 + ts.tv_usec/1000;
                }
                else
                {
                    strm_info->ts += DEF_TIMESTAMP;
                }

                write_stream_data((gpointer)strm_info->opened, 
                    (gulong)strm_info->ts, (gulong)DEF_TIMESTAMP, 
                    (guint8*)buffer, (gsize)buf_size, 
                    (guint8)data_type, (guint8*)NULL, (gsize)0, (guint8)0);
            }
            break;
    }
}