美文网首页
JRTPlib发送G711音频数据

JRTPlib发送G711音频数据

作者: 质子2 | 来源:发表于2018-04-17 17:21 被阅读0次
  • 将采集的pcm文件转码发送

- (void)DidGetAudioData:(void *const)buffer size:(int)dataSize andPts:(long long)pts
{
    if (self.silence)
    {
        return;
    }
    
    TEST *hehe=[[TEST alloc]init];
    
    int d=0;
    
    //pcmu 编码
    unsigned char requestBuf[dataSize / 2];
        
//    G711Encoder(buffer, requestBuf, (int)dataSize / 2, 1);
//转g711
    [hehe G711Encoder:buffer with:requestBuf with:(int)dataSize/2 with:1];

    long m=(sizeof(requestBuf)/320)+1;
    
    for (int i =0; i < m ;i++) {
        
        unsigned char buf[320];
        
        memset(buf, 0, sizeof(buf));
        
        for (int x= i*320; x < (i+1)*320 && x < dataSize / 2; x++) {

            buf[x-i*320]=requestBuf[x];

        }
        
        [RTPPack SendVideoPacket:buf Size:320];
        
        NSLog(@"%d---%d",dataSize,d++);
        
    }

    
    //解码
//    short decodeBuf[dataSize];
//
////    G711Decode(decodeBuf, requestBuf,dataSize);
//
//    [hehe G711Decode:decodeBuf with:requestBuf with:dataSize];
//
//    //播放
//    [self.pcmPlayer play:decodeBuf length:dataSize];
    
}

参考别人封装的

//发送数据
(void)SendVideoPacket:(unsigned char*)videoData
                   Size:(size_t)videoDataSize;

c++代码看不太懂,参考乔乐的代码

.h

#include "rtpsession.h"
#include "rtppacket.h"
#include "rtpudpv4transmitter.h"
#include "rtpipv4address.h"
#include "rtpsessionparams.h"
#include "rtperrors.h"

@interface VideoRTPPack : NSObject

{
    
    jrtplib::RTPSession m_RTPSession;

}

@property(nonatomic,strong)NSMutableDictionary *dicDataBuffer;

- (id)initWithVideoRTP:(NSString *)hostIP onPort:(unsigned short)port;

- (void)createVideoRTP:(NSString *)host onPort:(unsigned short)port;

- (void)SendVideoPacket:(unsigned char*)videoData
                   Size:(size_t)videoDataSize;

- (void)resendSubPacketData:(int)frameID withSubPack:(int)packID;

- (void)closeVideoRTP;

.mm

- (id)initWithVideoRTP:(NSString *)hostIP onPort:(unsigned short)port
{
    if (self = [super init])
    {
        [self createVideoRTP:hostIP onPort:port];
        
        _dicDataBuffer = [[NSMutableDictionary alloc] init];
    }
    
    return self;
}

- (void)dealloc
{
    
}

- (void)createVideoRTP:(NSString *)host onPort:(unsigned short)port
{
    jrtplib::RTPUDPv4TransmissionParams m_VideoTransparams;
    jrtplib::RTPSessionParams m_VideoSessionparams;
    
    m_VideoSessionparams.SetOwnTimestampUnit(1.0/8000.0);
    m_VideoSessionparams.SetAcceptOwnPackets(TRUE);
    m_VideoSessionparams.SetUsePollThread(0);
    m_VideoTransparams.SetPortbase(port);
    
    int nStatus = m_RTPSession.Create(m_VideoSessionparams, &m_VideoTransparams);
    
    if(nStatus < 0)
    {
        
        NSLog(@"create rtp faild!");
        
        return;
        
    }
    
    unsigned long ipAddress = ntohl(inet_addr([host UTF8String]));
    
    jrtplib::RTPIPv4Address JRTPVideoAddr;
    
    JRTPVideoAddr.SetIP(ipAddress);
    JRTPVideoAddr.SetPort(port);
    
    nStatus = m_RTPSession.AddDestination(JRTPVideoAddr);
    
    if(nStatus < 0)
    {
        
        NSLog(@"add destination faild!");
        
        return;
        
    }
    
    m_RTPSession.SetDefaultPayloadType(97);
    m_RTPSession.SetDefaultMark(false);
    m_RTPSession.SetDefaultTimestampIncrement(320);
    
}

- (void)SendVideoPacket:(unsigned char*)videoData
                   Size:(size_t)videoDataSize
{
   
//    m_RTPSession.SendPacket(videoData, videoDataSize);
    

    m_RTPSession.SendPacket(videoData, videoDataSize, 97, false, 320);
    
}

//重新发送
- (void)resendSubPacketData:(int)frameID withSubPack:(int)packID
{
    NSArray *lostArray = (NSArray *)[self.dicDataBuffer objectForKey:[NSNumber numberWithInt:frameID]];
    NSData *lostData = [lostArray objectAtIndex:packID-1];
    
    int nStatus = m_RTPSession.SendPacket([lostData bytes], [lostData length]);
    
    if (nStatus == 0)
    NSLog(@"ReSend Packet Data Succeed!");
}

- (void)closeVideoRTP
{
    if (m_RTPSession.IsActive())
    {
        m_RTPSession.Destroy();
    }
}

相关文章

  • JRTPlib发送G711音频数据

    将采集的pcm文件转码发送 参考别人封装的 c++代码看不太懂,参考乔乐的代码 .h .mm

  • G711音频编码

    原理 PCM是对模拟的连续信号进行抽样。G711则是对PCM数据进行再一次的抽样。G711主要是对16bit的PC...

  • AFNetworking 详解 以及 通过 POST 方式上传数

    POST 发送数据有两种形式:1、发送纯文本的内容2、发送的 body 部分带有文件(图片,音频或者其他二进制数据...

  • 发送音频空包

    在Rtmp和Voip通话过程中,有的时候,需要发送音频空包。这个时候需要替换音频包或者按照一定的频率发送音频空包。

  • WebRTC音频引擎实现分析

    WebRTC的音频引擎作为两大基础多媒体引擎之一,实现了音频数据的采集、前处理、编码、发送、接收、解码、混音、后处...

  • WebRTC 的音频数据编码及发送控制管线

    WebRTC 的音频数据处理发送的概念抽象层面的完整流程如下: AudioDeviceModule 用于控制各个操...

  • 简单问题却没解决的自我分析

    问题描述 : 实时采集音频流,并将音频信息发送给服务器,然而Okhttp在传递数据时却没有请求成,日志打印了"Sy...

  • iOS Audio Queue录制音频

    在开发中,我们有时候需要使用苹果相关音频框架录制音频数据,并同步保存在本地或发送到服务器,Audio Queue框...

  • 网络协议 UDP

    UDP 面向无连接的通讯协议,传输速度快,容易丢失数据。用广播发送数据,有可能会丢包。 视频,音频通讯,QQ也用U...

  • webrtc发送端-音频采集编码发送

    github:https://github.com/bigonelby/webrtcUml/tree/master...

网友评论

      本文标题:JRTPlib发送G711音频数据

      本文链接:https://www.haomeiwen.com/subject/bptpkftx.html