Ignore:
Timestamp:
Feb 21, 2006 12:11:18 AM (18 years ago)
Author:
bennylp
Message:

Initial conference implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/stream.c

    r188 r205  
    5353    pj_bool_t               paused;         /**< Paused?.                   */ 
    5454    pj_snd_stream_info      snd_info;       /**< Sound stream param.        */ 
    55     pj_snd_stream          *snd_stream;     /**< Sound stream.              */ 
     55    //pj_snd_stream        *snd_stream;     /**< Sound stream.              */ 
    5656    unsigned                in_pkt_size;    /**< Size of input buffer.      */ 
    5757    void                   *in_pkt;         /**< Input buffer.              */ 
     
    7373struct pjmedia_stream 
    7474{ 
     75    pjmedia_port             port;          /**< Port interface.            */ 
    7576    pjmedia_channel         *enc;           /**< Encoding channel.          */ 
    7677    pjmedia_channel         *dec;           /**< Decoding channel.          */ 
     
    103104 * needs to feed the player with some frames. 
    104105 */ 
    105 static pj_status_t play_callback(/* in */   void *user_data, 
    106                                  /* in */   pj_uint32_t timestamp, 
    107                                  /* out */  void *frame, 
    108                                  /*inout*/  unsigned size) 
    109 { 
    110     pjmedia_channel *channel = user_data; 
    111     pjmedia_stream *stream = channel->stream; 
     106static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) 
     107{ 
     108    pjmedia_stream *stream = port->user_data; 
     109    pjmedia_channel *channel = stream->dec; 
     110     
    112111    char frame_type; 
    113112    pj_status_t status; 
    114113    struct pjmedia_frame frame_in, frame_out; 
    115114 
    116     PJ_UNUSED_ARG(timestamp); 
    117  
    118115    /* Do nothing if we're quitting. */ 
    119     if (stream->quit_flag) 
    120         return -1; 
     116    if (stream->quit_flag) { 
     117        frame->type = PJMEDIA_FRAME_TYPE_NONE; 
     118        return PJ_SUCCESS; 
     119    } 
    121120 
    122121    /* Lock jitter buffer mutex */ 
     
    133132        frame_type == PJMEDIA_JB_MISSING_FRAME)  
    134133    { 
    135         pj_memset(frame, 0, size); 
    136         return 0; 
     134        frame->type = PJMEDIA_FRAME_TYPE_NONE; 
     135        return PJ_SUCCESS; 
    137136    } 
    138137 
     
    148147        TRACE_((THIS_FILE, "decode() has return error status %d", status)); 
    149148 
    150         pj_memset(frame, 0, size); 
    151         return 0; 
     149        frame->type = PJMEDIA_FRAME_TYPE_NONE; 
     150        return PJ_SUCCESS; 
    152151    } 
    153152 
    154153    /* Put in sound buffer. */ 
    155     if (frame_out.size > size) { 
     154    if (frame_out.size > frame->size) { 
    156155        TRACE_((THIS_FILE, "Sound playout buffer truncated %d bytes",  
    157                 frame_out.size - size)); 
    158         frame_out.size = size; 
    159     } 
    160  
    161     pj_memcpy(frame, frame_out.buf, size); 
    162  
    163     return 0; 
     156                frame_out.size - frame->size)); 
     157        frame_out.size = frame->size; 
     158    } 
     159 
     160    frame->type = PJMEDIA_FRAME_TYPE_AUDIO; 
     161    frame->size = frame_out.size; 
     162    frame->timestamp.u64 = 0; 
     163    pj_memcpy(frame->buf, frame_out.buf, frame_out.size); 
     164 
     165    return PJ_SUCCESS; 
    164166} 
    165167 
     
    172174 * send it to remote. 
    173175 */ 
    174 static pj_status_t rec_callback( /* in */ void *user_data, 
    175                                  /* in */ pj_uint32_t timestamp, 
    176                                  /* in */ const void *frame, 
    177                                  /* in */ unsigned size) 
    178 { 
    179     pjmedia_channel *channel = user_data; 
    180     pjmedia_stream *stream = channel->stream; 
     176static pj_status_t put_frame( pjmedia_port *port,  
     177                              const pjmedia_frame *frame ) 
     178{ 
     179    pjmedia_stream *stream = port->user_data; 
     180    pjmedia_channel *channel = stream->enc; 
    181181    pj_status_t status = 0; 
    182     struct pjmedia_frame frame_in, frame_out; 
     182    struct pjmedia_frame frame_out; 
    183183    int ts_len; 
    184184    void *rtphdr; 
     
    187187 
    188188 
    189     PJ_UNUSED_ARG(timestamp); 
    190  
    191189    /* Check if stream is quitting. */ 
    192190    if (stream->quit_flag) 
     
    194192 
    195193    /* Encode. */ 
    196     frame_in.type = PJMEDIA_TYPE_AUDIO; 
    197     frame_in.buf = (void*)frame; 
    198     frame_in.size = size; 
    199194    frame_out.buf = ((char*)channel->out_pkt) + sizeof(pjmedia_rtp_hdr); 
    200     status = stream->codec->op->encode( stream->codec, &frame_in,  
     195    status = stream->codec->op->encode( stream->codec, frame,  
    201196                                        channel->out_pkt_size - sizeof(pjmedia_rtp_hdr),  
    202197                                        &frame_out); 
     
    208203 
    209204    /* Encapsulate. */ 
    210     ts_len = size / (channel->snd_info.bits_per_sample / 8); 
     205    ts_len = frame->size / (channel->snd_info.bits_per_sample / 8); 
    211206    status = pjmedia_rtp_encode_rtp( &channel->rtp,  
    212207                                channel->pt, 0,  
     
    239234    stream->stat.enc.bytes += frame_out.size+sizeof(pjmedia_rtp_hdr); 
    240235 
    241     return 0; 
     236    return PJ_SUCCESS; 
    242237} 
    243238 
     
    426421    init_snd_param(&channel->snd_info, codec_param); 
    427422 
     423    /* 
    428424    if (dir == PJMEDIA_DIR_ENCODING) 
    429425        channel->snd_stream = pj_snd_open_recorder(-1, &channel->snd_info,  
     
    435431    if (!channel->snd_stream) 
    436432        return -1; 
    437  
     433    */ 
    438434 
    439435    /* Done. */ 
     
    463459    stream = pj_pool_zalloc(pool, sizeof(pjmedia_stream)); 
    464460    PJ_ASSERT_RETURN(stream != NULL, PJ_ENOMEM); 
     461 
     462    /* Init port. */ 
     463    stream->port.info.name = pj_str("stream"); 
     464    stream->port.info.signature = ('S'<<3 | 'T'<<2 | 'R'<<1 | 'M'); 
     465    stream->port.info.type = PJMEDIA_TYPE_AUDIO; 
     466    stream->port.info.has_info = 1; 
     467    stream->port.info.need_info = 0; 
     468    stream->port.info.pt = info->fmt.pt; 
     469    pj_strdup(pool, &stream->port.info.encoding_name, &info->fmt.encoding_name); 
     470    stream->port.info.sample_rate = info->fmt.sample_rate; 
     471    stream->port.user_data = stream; 
     472    stream->port.put_frame = &put_frame; 
     473    stream->port.get_frame = &get_frame; 
    465474 
    466475 
     
    495504        goto err_cleanup; 
    496505 
     506    /* Set additional info. */ 
     507    stream->port.info.bits_per_sample = 0; 
     508    stream->port.info.samples_per_frame = info->fmt.sample_rate*codec_param.ptime/1000; 
     509    stream->port.info.bytes_per_frame = codec_param.avg_bps/8 * codec_param.ptime/1000; 
     510 
    497511 
    498512    /* Open the codec: */ 
     
    576590    /* Close encoding sound stream. */ 
    577591     
     592    /* 
    578593    if (stream->enc && stream->enc->snd_stream) { 
    579594 
     
    583598 
    584599    } 
     600    */ 
    585601 
    586602    /* Close decoding sound stream. */ 
    587603 
     604    /* 
    588605    if (stream->dec && stream->dec->snd_stream) { 
    589606 
     
    593610 
    594611    } 
     612    */ 
    595613 
    596614    /* Wait for jitter buffer thread to quit: */ 
     
    623641 
    624642/* 
     643 * Get the port interface. 
     644 */ 
     645PJ_DEF(pj_status_t) pjmedia_stream_get_port( pjmedia_stream *stream, 
     646                                             pjmedia_port **p_port ) 
     647{ 
     648    *p_port = &stream->port; 
     649    return PJ_SUCCESS; 
     650} 
     651 
     652 
     653/* 
    625654 * Start stream. 
    626655 */ 
     
    632661    if (stream->enc && (stream->dir & PJMEDIA_DIR_ENCODING)) { 
    633662        stream->enc->paused = 0; 
    634         pj_snd_stream_start(stream->enc->snd_stream); 
     663        //pj_snd_stream_start(stream->enc->snd_stream); 
    635664    } 
    636665 
    637666    if (stream->dec && (stream->dir & PJMEDIA_DIR_DECODING)) { 
    638667        stream->dec->paused = 0; 
    639         pj_snd_stream_start(stream->dec->snd_stream); 
     668        //pj_snd_stream_start(stream->dec->snd_stream); 
    640669    } 
    641670 
Note: See TracChangeset for help on using the changeset viewer.