sk-3

sk-3

0个粉丝

6

问答

0

专栏

2

资料

sk-3  发布于  2015-01-05 09:08:58
采纳率 0%
6个问答
14400

ORTP移植hi3518 转

   

看到ORTP是纯C实现的rtp库,于是移植到3518e试用一下.

1.下载源码 http://www.linphone.org/technical-corner/ortp/downloads

里面有个tar res跳转链接跳转入

http://download.savannah.gnu.org/releases/linphone/ortp/sources/

下载最新的ortp-0.23.0.tar.gz,并解压

2.编译 ./configure --prefix=/work/hi3518/ortp --host=arm-hisiv100nptl-linux

make

make install

配置只需指定安装目录prefix,编译平台host即可,这里host直接赋值arm-hisiv100nptl-linux-gcc前缀即可,注意不是arm-hisiv100nptl-linux-而是arm-hisiv100nptl-linux。

3.部署到开发板 将编译生成的库/work/hi3518/ortp/lib/libortp.so.9复制到开发板/usr/lib中

4.添加ortp库到mpp2中 在海思SDK mpp2目录下新建rtp目录,将/work/hi3518/ortp/下全部内容复制到该目录下,

修改mpp2/sample/Makefile.param,添加:

INC_FLAGS += -I$(MPP_PATH)/rtp/include -L$(MPP_PATH)/rtp/lib/ -lortp

5.修改代码 示例程序venc中有将视频进行264编码并保存为文件(nfs挂载),这里一步步分析sample_venc.c即可找到最终的保存是通过sample_comm_venc.c中的SAMPLE_COMM_VENC_SaveH264函数完成的,这里只要修改该函数为封包发送即可。

下面是sample_comm_venc.c中需要添加的部分:

[objc] view plaincopy

include <ortp/ortp.h>

include

include

include <sys/types.h>

include <sys/time.h>

include

define Y_PLOAD_TYPE 96 //H.264

define MAX_RTP_PKT_LENGTH 1400

define DefaultTimestampIncrement 3600 //(90000/25)

uint32_t g_userts=0;
RtpSession *pRtpSession = NULL;
/** 初始化

  • 主要用于对ortp以及其它参数进行初始化
  • @param: char * ipStr 目的端IP地址描述串
  • @param: iint port 目的端RTP监听端口
  • @return: RtpSession * 返回指向RtpSession对象的指针,如果为NULL,则初始化失败
  • @note:
    /
    RtpSession
    rtpInit( char ipStr, int port)
    {
    RtpSession
    session;
    char *ssrc;
    printf("****oRTP for H.264 Init****\n");

    ortp_init();
    ortp_scheduler_init();
    ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
    session=rtp_session_new(RTP_SESSION_SENDONLY);

    rtp_session_set_scheduling_mode(session,1);
    rtp_session_set_blocking_mode(session,0);
    //rtp_session_set_connected_mode(session,TRUE);
    rtp_session_set_remote_addr(session,ipStr,port);
    rtp_session_set_payload_type(session,Y_PLOAD_TYPE);

    ssrc=getenv("SSRC");
    if (ssrc!=NULL) {
    printf("using SSRC=%i.\n",atoi(ssrc));
    // 设置输出流的SSRC。不做此步的话将会给个随机值
    rtp_session_set_ssrc(session,atoi(ssrc));
    }
    return session;
    }
    /** 结束ortp的发送,释放资源

  • @param: RtpSession *session RTP会话对象的指针
  • @return: 0表示成功
  • @note:
    /
    int rtpExit(RtpSession
    session)
    {
    printf("****oRTP for H.264 Exit****\n");
    g_userts = 0;

    rtp_session_destroy(session);
    ortp_exit();
    ortp_global_stats_display();

    return 0;
    }
    /** 发送rtp数据包

  • 主要用于发送rtp数据包
  • @param: RtpSession *session RTP会话对象的指针
  • @param: const char *buffer 要发送的数据的缓冲区地址
    • @param: int len 要发送的数据长度
  • @return: int 实际发送的数据包数目
  • @note: 如果要发送的数据包长度大于BYTES_PER_COUNT,本函数内部会进行分包处理
    /
    int rtpSend(RtpSession
    session, char *buffer, int len)
    {
    int sendBytes = 0;
    int status;
    uint32_t valid_len=len-4;
    unsigned char NALU=buffer[4];

    //printf("send len=%d\n",len);

    //如果数据小于MAX_RTP_PKT_LENGTH字节,直接发送:单一NAL单元模式
    if(valid_len <= MAX_RTP_PKT_LENGTH)
    {
    sendBytes = rtp_session_send_with_ts(session,
    &buffer[4],
    valid_len,
    g_userts);
    return sendBytes;
    }
    else if (valid_len > MAX_RTP_PKT_LENGTH)
    {
    //切分为很多个包发送,每个包前要对头进行处理,如第一个包
    valid_len -= 1;
    int k=0,l=0;
    k=valid_len/MAX_RTP_PKT_LENGTH;
    l=valid_len%MAX_RTP_PKT_LENGTH;
    int t=0;
    int pos=5;
    if(l!=0)
    {
    k=k+1;
    }
    while(t<k)//||(t==k&&l>0))
    {
    if(t<(k-1))//(t<k&&l!=0)||(t<(k-1))&&(l==0))//(0==t)||(t<k&&0!=l))
    {
    buffer[pos-2]=(NALU & 0x60)|28;
    buffer[pos-1]=(NALU & 0x1f);
    if(0==t)
    {
    buffer[pos-1]|=0x80;
    }
    sendBytes = rtp_session_send_with_ts(session,
    &buffer[pos-2],
    MAX_RTP_PKT_LENGTH+2,
    g_userts);
    t++;
    pos+=MAX_RTP_PKT_LENGTH;
    }
    else //if((k==t&&l>0)||((t==k-1)&&l==0))
    {
    int iSendLen;
    if(l>0)
    {
    iSendLen=valid_len-t*MAX_RTP_PKT_LENGTH;
    }
    else
    iSendLen=MAX_RTP_PKT_LENGTH;
    buffer[pos-2]=(NALU & 0x60)|28;
    buffer[pos-1]=(NALU & 0x1f);
    buffer[pos-1]|=0x40;
    sendBytes = rtp_session_send_with_ts(session,
    &buffer[pos-2],
    iSendLen+2,
    g_userts);
    t++;
    }
    }
    }

    g_userts += DefaultTimestampIncrement;//timestamp increase
    return len;
    }
    在实现调用前需要进行ortp加载初始化,我们在该文件中的函数SAMPLE_COMM_VENC_GetVencStreamProc中添加初始化即可:

[objc] view plaincopy /*rtp init**/
pRtpSession = rtpInit( "129.1.4.196" ,8080);
if (pRtpSession==NULL)
{
printf( "error rtpInit" );
exit(-1);
return 0;
}

/** step 2: Start to get streams of each channel. **/
注:这里为了简便在程序中写死了发送目标为129.1.4.196:8080,这要与下面的cfg.sdp对应.

然后修改SAMPLE_COMM_VENC_SaveH264函数调用rtp发送: [objc] view plaincopy /*****

  • funciton : save H264 stream **/
    HI_S32 SAMPLE_COMM_VENC_SaveH264(FILE fpH264File, VENC_STREAM_S pstStream)
    {
    HI_S32 i;

    for (i = 0; i < pstStream->u32PackCount; i++)
    {

    if 0

    fwrite(pstStream->pstPack[i].pu8Addr[0],  
           pstStream->pstPack[i].u32Len[0], 1, fpH264File);  
    
    fflush(fpH264File);  
    
    if (pstStream->pstPack[i].u32Len[1] > 0)  
    {  
        fwrite(pstStream->pstPack[i].pu8Addr[1],  
               pstStream->pstPack[i].u32Len[1], 1, fpH264File);  
    
        fflush(fpH264File);  
    }  
    #else  
    rtpSend(pRtpSession,  
            pstStream->pstPack[i].pu8Addr[0],  
            pstStream->pstPack[i].u32Len[0]);  
    if (pstStream->pstPack[i].u32Len[1] > 0)  
    {  
        rtpSend(pRtpSession,  
                pstStream->pstPack[i].pu8Addr[1],  
                pstStream->pstPack[i].u32Len[1]);  
    }  
    #endif  

    }

    return HI_SUCCESS;
    }
    这样编译获得 sample_venc.

6.运行

将sample_venc加载到开发板并运行,

./sample_venc 0

please press twice ENTER to exit this sample

****oRTP for H.264 Init****

Av profile add H.264

ortp-message-Setting random local addresses.

ortp-message-rtp session [0x1c95758] set to rtp [129.1.4.196:8080] rtcp [129.1.4.196:8081]

ortp-message-Using permissive algorithm

ortp-message-Sending RTCP SR compound message on session [0x1c95758].

ortp-message-Sending RTCP SR compound message on session [0x1c95758].

......

7.VLC播放

PC端使用VLC来播放,编写cfg.sdp如下:

[plain] view plaincopy m=video 8080 RTP/AVP 96
a=rtpmap:96 H264/90000;
a=decode_buf=300;
a=framerate:25
c=IN IP4 129.1.4.196
这里129.1.4.196即为PC的IP,Port8080为监控rtp使用端口,payloadtype为96,即h.264. VLC能够正常播放,但有延时。 //================================================================================= 是可以播放的,库中确实需要添加: rtp_profile_set_payload(&av_profile, 96, &payload_type_h264); 注意例子是启动了三路venc,需要改为一路。 不过有问题,播放过程中提示: Segmentation fault

http://blog.csdn.net/jiaozi07/article/details/41749943

我来回答
回答8个
时间排序
认可量排序

一直未离开

0个粉丝

0

问答

0

专栏

0

资料

一直未离开 2015-01-09 15:42:44
认可0
这个必须顶。

jinzhang07

0个粉丝

2

问答

0

专栏

1

资料

jinzhang07 2015-01-24 12:38:10
认可0
呵呵 在论坛看到自己的文章。。。。。

cs_sos

0个粉丝

9

问答

2

专栏

5

资料

cs_sos 2015-01-24 13:58:53
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=11742&ptid=4956]jinzhang07 发表于 2015-1-24 12:38[/url]
呵呵 在论坛看到自己的文章。。。。。[/quote]

期待大作,我等膜拜 :)

duikang

0个粉丝

0

问答

0

专栏

0

资料

duikang 2015-01-26 19:33:29
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=11742&ptid=4956]jinzhang07 发表于 2015-1-24 12:38[/url]
呵呵 在论坛看到自己的文章。。。。。[/quote]

前辈,用你的方案VLC打开sdp,没有看到图像就崩溃推出了,是什么问题

zhitao2072

0个粉丝

0

问答

0

专栏

0

资料

zhitao2072 2015-01-28 11:18:47
认可0
支持一下,有空试试

3518hi

0个粉丝

0

问答

0

专栏

0

资料

3518hi 2015-06-25 16:54:56
认可0
ortp-message-Sending RTCP SR compound message on session [0x5f7758].
ortp-message-Sending RTCP SR compound message on session [0x5f7758].
ortp-message-Sending RTCP SR compound message on session [0x5f7758].
ortp-message-Sending RTCP SR compound message on session [0x5f7758].
ortp-message-Sending RTCP SR compound message on session [0x5f7758].
Segmentation fault



运行一段时间  就会崩溃
:Q:Q:Q:Q

fishcrane

0个粉丝

9

问答

0

专栏

0

资料

fishcrane 2016-09-23 19:16:32
认可0
按照您的方式为什么运行会提示rtp/lib//libortp.so 时跳过不兼容的 -lortp
arm-hisiv400-linux-gnueabi/bin/ld: 找不到 -lortp

请教

zcc246

0个粉丝

1

问答

0

专栏

0

资料

zcc246 2016-10-16 23:25:08
认可0
[quote][url=forum.php?mod=redirect&goto=findpost&pid=17493&ptid=4956]3518hi 发表于 2015-6-25 16:54[/url]
ortp-message-Sending RTCP SR compound message on session [0x5f7758].
ortp-message-Sending RTCP SR c ...[/quote]

您好 我想问下 最后调好没 我现在运行一段时间后就Segmentation fault 能告诉解决方法吗?
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
相关问答
无更多相似问答 去提问
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区