modules/media/src/main/native/gstreamer/plugins/audioconverter/audioconverter.c

Print this page
rev 8792 : imported patch 8u45.patch

*** 642,656 **** GstClockTime buf_time = GST_BUFFER_TIMESTAMP(buf); // If between FLUSH_START and FLUSH_STOP, reject new buffers. if (decode->is_flushing) { ! // Unref the input buffer. ! // INLINE - gst_buffer_unref() ! gst_buffer_unref(buf); ! ! return GST_FLOW_WRONG_STATE; } // Reset state on discont buffer if not after FLUSH_STOP. if (GST_BUFFER_IS_DISCONT(buf) && TRUE == decode->is_synced) { audioconverter_state_reset(decode); --- 642,653 ---- GstClockTime buf_time = GST_BUFFER_TIMESTAMP(buf); // If between FLUSH_START and FLUSH_STOP, reject new buffers. if (decode->is_flushing) { ! ret = GST_FLOW_WRONG_STATE; ! goto _exit; } // Reset state on discont buffer if not after FLUSH_STOP. if (GST_BUFFER_IS_DISCONT(buf) && TRUE == decode->is_synced) { audioconverter_state_reset(decode);
*** 744,760 **** } decode->isFormatInitialized = TRUE; decode->isAudioConverterReady = TRUE; } else { - // Unref the input buffer. - // INLINE - gst_buffer_unref() - gst_buffer_unref(buf); - gst_caps_unref(sink_peer_caps); ! return GST_FLOW_ERROR; } } else { gint layer; if(gst_structure_get_int(caps_struct, "layer", &layer)) { switch(layer) { --- 741,754 ---- } decode->isFormatInitialized = TRUE; decode->isAudioConverterReady = TRUE; } else { gst_caps_unref(sink_peer_caps); ! ret = GST_FLOW_ERROR; ! goto _exit; } } else { gint layer; if(gst_structure_get_int(caps_struct, "layer", &layer)) { switch(layer) {
*** 784,801 **** if(noErr != AudioFileStreamOpen((void*)decode, propertyListener, packetListener, audioStreamTypeHint, &decode->audioStreamID)) { - // Unref the input buffer. - // INLINE - gst_buffer_unref() - gst_buffer_unref(buf); - #if ENABLE_PRINT_SPEW g_print("AudioFileStreamOpen failed\n"); #endif ! return GST_FLOW_ERROR; } } } if(decode->enable_parser) { --- 778,792 ---- if(noErr != AudioFileStreamOpen((void*)decode, propertyListener, packetListener, audioStreamTypeHint, &decode->audioStreamID)) { #if ENABLE_PRINT_SPEW g_print("AudioFileStreamOpen failed\n"); #endif ! ret = GST_FLOW_ERROR; ! goto _exit; } } } if(decode->enable_parser) {
*** 812,830 **** } } OSStatus result = AudioFileStreamParseBytes(decode->audioStreamID, buf_size, buf_data, parserFlags); - // Unref the input buffer. - // INLINE - gst_buffer_unref() - gst_buffer_unref(buf); - if(noErr != result) { #if ENABLE_PRINT_SPEW g_print("AudioFileStreamParseBytes %d\n", result); #endif ! return GST_FLOW_ERROR; } } else { if(!decode->is_synced && NULL != decode->audioConverter) { AudioConverterReset(decode->audioConverter); } --- 803,818 ---- } } OSStatus result = AudioFileStreamParseBytes(decode->audioStreamID, buf_size, buf_data, parserFlags); if(noErr != result) { #if ENABLE_PRINT_SPEW g_print("AudioFileStreamParseBytes %d\n", result); #endif ! ret = GST_FLOW_ERROR; ! goto _exit; } } else { if(!decode->is_synced && NULL != decode->audioConverter) { AudioConverterReset(decode->audioConverter); }
*** 834,857 **** packetDescriptions.mStartOffset = 0; packetDescriptions.mVariableFramesInPacket = 0; packetListener((void*)decode, buf_size, 1, (const void*)buf_data, &packetDescriptions); - - // Unref the input buffer. - // INLINE - gst_buffer_unref() - gst_buffer_unref(buf); } // Return without pushing a buffer if format not derived from stream parser. if(!decode->isFormatInitialized) { return GST_FLOW_OK; } // Return without pushing a buffer if format is MPEG audio but no packets are enqueued. if(AUDIOCONVERTER_DATA_FORMAT_MPA == decode->data_format && 0 == decode->total_packets) { ! return GST_FLOW_OK; } if(decode->is_synced == FALSE) { // Set flags. gboolean is_first_frame = !decode->is_initialized; --- 822,841 ---- packetDescriptions.mStartOffset = 0; packetDescriptions.mVariableFramesInPacket = 0; packetListener((void*)decode, buf_size, 1, (const void*)buf_data, &packetDescriptions); } // Return without pushing a buffer if format not derived from stream parser. if(!decode->isFormatInitialized) { return GST_FLOW_OK; } // Return without pushing a buffer if format is MPEG audio but no packets are enqueued. if(AUDIOCONVERTER_DATA_FORMAT_MPA == decode->data_format && 0 == decode->total_packets) { ! goto _exit; // GST_FLOW_OK } if(decode->is_synced == FALSE) { // Set flags. gboolean is_first_frame = !decode->is_initialized;
*** 868,886 **** if(is_first_frame) { // Allocate memory for output packet descriptions. decode->outPacketDescription = g_malloc(decode->samples_per_frame*sizeof(AudioStreamPacketDescription)); if(NULL == decode->outPacketDescription) { ! return GST_FLOW_ERROR; } // Save first frame offset. ! if (GST_BUFFER_OFFSET_IS_VALID(buf)) { ! decode->initial_offset = GST_BUFFER_OFFSET(buf); ! } else { ! decode->initial_offset = 0; ! } // Query for the stream length if it was not set from a header. if (AUDIOCONVERTER_STREAM_LENGTH_UNKNOWN == decode->stream_length) { GstFormat sink_format = GST_FORMAT_BYTES; --- 852,867 ---- if(is_first_frame) { // Allocate memory for output packet descriptions. decode->outPacketDescription = g_malloc(decode->samples_per_frame*sizeof(AudioStreamPacketDescription)); if(NULL == decode->outPacketDescription) { ! ret = GST_FLOW_ERROR; ! goto _exit; } // Save first frame offset. ! decode->initial_offset = GST_BUFFER_OFFSET_IS_VALID(buf) ? GST_BUFFER_OFFSET(buf) : 0; // Query for the stream length if it was not set from a header. if (AUDIOCONVERTER_STREAM_LENGTH_UNKNOWN == decode->stream_length) { GstFormat sink_format = GST_FORMAT_BYTES;
*** 931,941 **** } else if(AUDIOCONVERTER_DATA_FORMAT_AAC == decode->data_format) { caps = gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 2, NULL); } else { ! return GST_FLOW_ERROR; } if(gst_pad_set_caps (decode->sinkpad, caps) == FALSE) { #if ENABLE_PRINT_SPEW --- 912,923 ---- } else if(AUDIOCONVERTER_DATA_FORMAT_AAC == decode->data_format) { caps = gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 2, NULL); } else { ! ret = GST_FLOW_ERROR; ! goto _exit; } if(gst_pad_set_caps (decode->sinkpad, caps) == FALSE) { #if ENABLE_PRINT_SPEW
*** 981,1009 **** } } if(!decode->isAudioConverterReady) { // Return without pushing a buffer if converter is not ready. ! return GST_FLOW_OK; } else if(NULL == decode->audioConverter) { // Initialize the converter. if(noErr != AudioConverterNew(&decode->audioInputFormat, &decode->audioOutputFormat, &decode->audioConverter)) { #if ENABLE_PRINT_SPEW g_print("Failed to initialize AudioConverter\n"); #endif // Return an error if converter cannot be initialized. ! return GST_FLOW_ERROR; } else if(NULL != decode->cookieData && noErr != AudioConverterSetProperty(decode->audioConverter, kAudioConverterDecompressionMagicCookie, decode->cookieSize, decode->cookieData)) { #if ENABLE_PRINT_SPEW g_print("Failed to set AudioConverter magic cookie data\n"); #endif // Return an error if converter cannot be initialized. ! return GST_FLOW_ERROR; } else if(AUDIOCONVERTER_DATA_FORMAT_AAC == decode->data_format) { AudioConverterPrimeInfo primeInfo; primeInfo.leadingFrames = 0; primeInfo.trailingFrames = 0; AudioConverterSetProperty(decode->audioConverter, kAudioConverterPrimeInfo, --- 963,993 ---- } } if(!decode->isAudioConverterReady) { // Return without pushing a buffer if converter is not ready. ! goto _exit; // GST_FLOW_OK } else if(NULL == decode->audioConverter) { // Initialize the converter. if(noErr != AudioConverterNew(&decode->audioInputFormat, &decode->audioOutputFormat, &decode->audioConverter)) { #if ENABLE_PRINT_SPEW g_print("Failed to initialize AudioConverter\n"); #endif // Return an error if converter cannot be initialized. ! ret = GST_FLOW_ERROR; ! goto _exit; } else if(NULL != decode->cookieData && noErr != AudioConverterSetProperty(decode->audioConverter, kAudioConverterDecompressionMagicCookie, decode->cookieSize, decode->cookieData)) { #if ENABLE_PRINT_SPEW g_print("Failed to set AudioConverter magic cookie data\n"); #endif // Return an error if converter cannot be initialized. ! ret = GST_FLOW_ERROR; ! goto _exit; } else if(AUDIOCONVERTER_DATA_FORMAT_AAC == decode->data_format) { AudioConverterPrimeInfo primeInfo; primeInfo.leadingFrames = 0; primeInfo.trailingFrames = 0; AudioConverterSetProperty(decode->audioConverter, kAudioConverterPrimeInfo,
*** 1021,1031 **** } if(decode->is_priming) { // Return without pushing a buffer if there are not enough packets enqueued. if(g_queue_get_length(decode->packetDesc) < AUDIOCONVERTER_MPEG_MIN_PACKETS) { ! return GST_FLOW_OK; } else { decode->is_priming = FALSE; } } --- 1005,1015 ---- } if(decode->is_priming) { // Return without pushing a buffer if there are not enough packets enqueued. if(g_queue_get_length(decode->packetDesc) < AUDIOCONVERTER_MPEG_MIN_PACKETS) { ! goto _exit; // GST_FLOW_OK; } else { decode->is_priming = FALSE; } }
*** 1045,1055 **** if (ret != GST_FLOW_WRONG_STATE) { gst_element_message_full(GST_ELEMENT(decode), GST_MESSAGE_ERROR, GST_CORE_ERROR, GST_CORE_ERROR_SEEK, g_strdup("Decoded audio buffer allocation failed"), NULL, ("audioconverter.c"), ("audioconverter_chain"), 0); } ! return ret; } AudioBufferList outputData; outputData.mNumberBuffers = 1; outputData.mBuffers[0].mNumberChannels = decode->audioOutputFormat.mChannelsPerFrame; --- 1029,1039 ---- if (ret != GST_FLOW_WRONG_STATE) { gst_element_message_full(GST_ELEMENT(decode), GST_MESSAGE_ERROR, GST_CORE_ERROR, GST_CORE_ERROR_SEEK, g_strdup("Decoded audio buffer allocation failed"), NULL, ("audioconverter.c"), ("audioconverter_chain"), 0); } ! goto _exit; } AudioBufferList outputData; outputData.mNumberBuffers = 1; outputData.mBuffers[0].mNumberChannels = decode->audioOutputFormat.mChannelsPerFrame;
*** 1065,1075 **** #if ENABLE_PRINT_SPEW g_print("AudioConverterFillComplexBuffer err: %u\n", err); #endif // INLINE - gst_buffer_unref() gst_buffer_unref(outbuf); ! return GST_FLOW_ERROR; } if(0 == outputDataPacketSize) { // INLINE - gst_buffer_unref() gst_buffer_unref(outbuf); --- 1049,1060 ---- #if ENABLE_PRINT_SPEW g_print("AudioConverterFillComplexBuffer err: %u\n", err); #endif // INLINE - gst_buffer_unref() gst_buffer_unref(outbuf); ! ret = GST_FLOW_ERROR; ! goto _exit; } if(0 == outputDataPacketSize) { // INLINE - gst_buffer_unref() gst_buffer_unref(outbuf);
*** 1093,1103 **** decode->is_discont = FALSE; } ret = gst_pad_push (decode->srcpad, outbuf); if(GST_FLOW_OK != ret) { ! return ret; } } // Remove processed bytes from the buffer cache. if(decode->inputOffset != 0) --- 1078,1088 ---- decode->is_discont = FALSE; } ret = gst_pad_push (decode->srcpad, outbuf); if(GST_FLOW_OK != ret) { ! goto _exit; } } // Remove processed bytes from the buffer cache. if(decode->inputOffset != 0)
*** 1106,1116 **** decode->inputOffset <= decode->inputData->len ? decode->inputOffset : decode->inputData->len); decode->inputOffset = 0; } ! return GST_FLOW_OK; } #if ENABLE_PRINT_SPEW static void printStreamDesc (AudioStreamBasicDescription* d) { g_print ("%lf %d %d %d %d %d %d %d %d\n", --- 1091,1105 ---- decode->inputOffset <= decode->inputData->len ? decode->inputOffset : decode->inputData->len); decode->inputOffset = 0; } ! _exit: ! // Unref the input buffer. ! // INLINE - gst_buffer_unref() ! gst_buffer_unref(buf); ! return ret; } #if ENABLE_PRINT_SPEW static void printStreamDesc (AudioStreamBasicDescription* d) { g_print ("%lf %d %d %d %d %d %d %d %d\n",