ismacryp_rc_t ismacrypDecryptSampleRemoveHeader (ismacryp_session_id_t session, uint32_t length, uint8_t *data, uint32_t *new_length, uint8_t **new_data) { ismacryp_session_t *sp; #ifndef NULL_ISMACRYP err_status_t rc = err_status_ok; #endif uint8_t *temp_data; int header_length; int i; uint32_t *IV; if (findInSessionList(session, &sp)) { fprintf(stdout, "Failed to decrypt+remove header. Unknown session %d \n", session); return ismacryp_rc_sessid_error; } sp->sample_count++; if (sp->selective_enc ) { fprintf(stdout," Selective encryption is not supported.\n"); return ismacryp_rc_unsupported_error; } else { header_length = ISMACRYP_DEFAULT_KEYINDICATOR_LENGTH + sp->IV_len; IV = (uint32_t *)(&data[header_length - sizeof(uint32_t)]); *new_length = length - header_length; temp_data = (uint8_t *) malloc((size_t) *new_length); if ( temp_data == NULL ) { fprintf(stdout, "Failed to decrypt+remove header, mem error. Session %d \n", session); return ismacryp_rc_memory_error; } memcpy(temp_data, &data[header_length], *new_length); } ismacrypDecryptSampleRandomAccess(session, ntohl(*IV), *new_length, temp_data); *new_data = temp_data; return ismacryp_rc_ok; }
static bool start_next_frame (rtp_plugin_data_t *pifptr, uint8_t **buffer, uint32_t *buflen, frame_timestamp_t *ts, void **userdata) { isma_enc_rtp_data_t *iptr = (isma_enc_rtp_data_t *)pifptr; uint64_t timetick; if (iptr->m_frame_data_on != NULL) { uint32_t next_ts; #ifdef DEBUG_ISMA_AAC isma_message(LOG_DEBUG, ismaencrtp, "Advancing to next pak data - old ts %x", iptr->m_frame_data_on->rtp_timestamp); #endif if (iptr->m_frame_data_on->last_in_pak != 0) { // We're done with all the data in this packet - get rid // of the rtp packet. if (iptr->m_frame_data_on->is_fragment == 1) { // if fragmented, need to get rid of all paks pointed to isma_frag_data_t *q = iptr->m_frame_data_on->frag_data; while (q != NULL) { rtp_packet *pak = q->pak; q->pak = NULL; if (pak != NULL) { iptr->m_vft->free_pak(pak); } q = q->frag_data_next; #ifdef DEBUG_ISMA_AAC isma_message(LOG_DEBUG, ismaencrtp, "removing pak - frag %d", pak->rtp_pak_seq); #endif } } else { rtp_packet *pak = iptr->m_frame_data_on->pak; iptr->m_frame_data_on->pak = NULL; iptr->m_vft->free_pak(pak); #ifdef DEBUG_ISMA_AAC isma_message(LOG_DEBUG, ismaencrtp, "removing pak %d", pak->rtp_pak_seq); #endif } } /* * Remove the frame data head pointer, and put it on the free list */ isma_frame_data_t *p = NULL; SDL_LockMutex(iptr->m_rtp_packet_mutex); p = iptr->m_frame_data_on; iptr->m_frame_data_on = NULL; next_ts = p->rtp_timestamp; p->frame_data_next = iptr->m_frame_data_free; iptr->m_frame_data_free = p; // free all frag_data for this frame if (p->is_fragment == 1) { isma_frag_data_t * q = p->frag_data; while (q != NULL) { p->frag_data = q->frag_data_next; CHECK_AND_FREE(q); q = p->frag_data; } } SDL_UnlockMutex(iptr->m_rtp_packet_mutex); /* * Now, look for the next timestamp - process a bunch of new * rtp packets, if we have to... */ next_ts += iptr->m_rtp_ts_add; if (iptr->m_frame_data_head == NULL || iptr->m_frame_data_head->rtp_timestamp != next_ts) { // process next pak in list. Process until next timestamp is found, // or 500 msec worth of data is found (in which case, go with first) do { process_packet_header(iptr); } while (iptr->m_vft->get_next_pak(iptr->m_ifptr, NULL, 0) != NULL && ((iptr->m_frame_data_head == NULL) || (iptr->m_frame_data_head->rtp_timestamp != next_ts)) && (iptr->m_frame_data_free != NULL)); } #ifdef DEBUG_ISMA_AAC else { // iptr->m_frame_data_head is correct isma_message(LOG_DEBUG, ismaencrtp, "frame_data_head is correct"); } #endif } else { // first time. Process a bunch of packets, go with first one... // asdf - will want to eventually add code to drop the first couple // of packets if they're not consecutive. do { process_packet_header(iptr); } while (iptr->m_frame_data_free != NULL); } /* * Init up the offsets */ if (iptr->m_frame_data_head != NULL) { SDL_LockMutex(iptr->m_rtp_packet_mutex); iptr->m_frame_data_on = iptr->m_frame_data_head; iptr->m_frame_data_head = iptr->m_frame_data_head->frame_data_next; SDL_UnlockMutex(iptr->m_rtp_packet_mutex); if (iptr->m_frame_data_on->is_fragment == 1) { iptr->m_frag_reass_size = 0; isma_frag_data_t *ptr; ptr = iptr->m_frame_data_on->frag_data; while (ptr != NULL) { if (iptr->m_frag_reass_size + ptr->frag_len > iptr->m_frag_reass_size_max) { iptr->m_frag_reass_size_max += MAX(4096, ptr->frag_len); iptr->m_frag_reass_buffer = (uint8_t *)realloc(iptr->m_frag_reass_buffer, iptr->m_frag_reass_size_max); } memmove(iptr->m_frag_reass_buffer + iptr->m_frag_reass_size, ptr->frag_ptr, ptr->frag_len); iptr->m_frag_reass_size += ptr->frag_len; ptr = ptr->frag_data_next; } *buffer = iptr->m_frag_reass_buffer; *buflen = iptr->m_frag_reass_size; } else { *buffer = iptr->m_frame_data_on->frame_ptr; *buflen = iptr->m_frame_data_on->frame_len; } } else { *buffer = NULL; } #ifdef ISMA_RTP_DUMP_OUTPUT_TO_FILE if (*buffer != NULL) { fwrite(*buffer, *buflen, 1, iptr->m_outfile); } #endif timetick = iptr->m_vft->rtp_ts_to_msec(iptr->m_ifptr, iptr->m_frame_data_on != NULL ? iptr->m_frame_data_on->rtp_timestamp : iptr->m_ts, iptr->m_frame_data_on ? iptr->m_frame_data_on->pak->pd.rtp_pd_timestamp : 0, 0); if (iptr->m_frame_data_on != NULL) iptr->m_ts = iptr->m_frame_data_on->rtp_timestamp; // We're going to have to handle wrap better... #ifdef DEBUG_ISMA_AAC isma_message(LOG_DEBUG, ismaencrtp, "start next frame %p %d ts "LLX" "LLU, *buffer, *buflen, iptr->m_ts, timetick); #endif ismacrypDecryptSampleRandomAccess(iptr->myEncSID, iptr->m_frame_data_on->IV, *buflen, *buffer); ts->audio_freq_timestamp = iptr->m_ts; ts->msec_timestamp = timetick; ts->timestamp_is_pts = true; return (true); }