Added new API for configuration via media format 52/137852/12 submit/tizen/20170718.022909
authorSejun Park <sejun79.park@samsung.com>
Mon, 10 Jul 2017 06:25:19 +0000 (15:25 +0900)
committerSejun Park <sejun79.park@samsung.com>
Thu, 13 Jul 2017 06:47:13 +0000 (15:47 +0900)
Change-Id: I03b67183493b9c1e97136c0c213ad6234901fe7f

include/media_codec.h
include/media_codec_port.h
src/media_codec.c
src/media_codec_port.c
test/media_codec_test.c

index b6fa990..8e6aa3c 100644 (file)
@@ -133,8 +133,8 @@ typedef enum {
  * @brief Called when the input buffer(pkt) used up.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @details It will be invoked when mediacodec has used input buffer.
- * @param[in] pkt  The media packet handle
- * @param[in] user_data  The user data passed from the callback registration function
+ * @param[in] pkt       The media packet handle
+ * @param[in] user_data The user data passed from the callback registration function
  * @pre It will be invoked when input buffer process completed if you register this callback using mediacodec_set_input_buffer_used_cb().
  * @see mediacodec_set_input_buffer_used_cb()
  * @see mediacodec_unset_input_buffer_used_cb()
@@ -145,8 +145,8 @@ typedef void (*mediacodec_input_buffer_used_cb)(media_packet_h pkt, void *user_d
  * @brief Called when the output buffer is available.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @details It will be invoked when mediacodec has output buffer.
- * @param[in] pkt  The media packet handle
- * @param[in] user_data  The user data passed from the callback registration function
+ * @param[in] pkt       The media packet handle
+ * @param[in] user_data The user data passed from the callback registration function
  * @pre It will be invoked when mediacodec process completed(had output buffer) if you register this callback using mediacodec_set_fill_buffer_cb().
  * @see mediacodec_set_output_buffer_available_cb()
  * @see mediacodec_unset_output_buffer_available_cb()
@@ -157,7 +157,7 @@ typedef void (*mediacodec_output_buffer_available_cb)(media_packet_h pkt, void *
  * @brief Called when the error has occured
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @details It will be invoked when the error has occured.
- * @param[in] error_code  The error code
+ * @param[in] error_code The error code
  * @param[in] user_data  The user data passed from the callback registration function
  * @pre It will be invoked when the error has occured if you register this callback using mediacodec_set_error_cb().
  * @see mediacodec_set_error_cb()
@@ -169,7 +169,7 @@ typedef void (*mediacodec_error_cb)(mediacodec_error_e error, void *user_data);
  * @brief Called when there is no data to decode/encode
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @details It will be invoked when the end-of-stream is reached.
- * @param[in] user_data  The user data passed from the callback registration function
+ * @param[in] user_data The user data passed from the callback registration function
  * @pre It will be invoked when the eos event generate if you register this callback using mediacodec_set_eos_cb().
  * @see mediacodec_set_eos_cb()
  * @see mediacodec_unset_eos_cb()
@@ -181,7 +181,7 @@ typedef void (*mediacodec_eos_cb)(void *user_data);
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  * @details It is recommended that the application stops calling mediacodec_process_input() when MEDIACODEC_ENOUGH_DATA
  * is invoked.
- * @param[in] user_data  The user data passed from the callback registration function
+ * @param[in] user_data The user data passed from the callback registration function
  * @see mediacodec_set_buffer_status_cb()
  * @see mediacodec_unset_buffer_status_cb()
  */
@@ -206,7 +206,7 @@ typedef bool (*mediacodec_supported_codec_cb)(mediacodec_codec_type_e codec_type
  *          the mediacodec cannot guarantee proper operation because of limited resources, like
  *          audio or display device.
  *
- * @param[out]  mediacodec  A new handle to mediacodec
+ * @param[out] mediacodec  A new handle to mediacodec
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -221,7 +221,7 @@ int mediacodec_create(mediacodec_h *mediacodec);
  * @remarks To completely shutdown the mediacodec operation, call this function with a valid player handle from any
  *          mediacodec
  *
- * @param[in]  mediacodec  The handle to mediacodec to be destroyed.
+ * @param[in] mediacodec The handle to mediacodec to be destroyed.
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -252,9 +252,9 @@ int mediacodec_set_codec(mediacodec_h mediacodec, mediacodec_codec_type_e codec_
 /**
  * @brief Sets the default info for the video decoder
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
- * @param[in] width  The width for video decoding.
- * @param[in] height  The height for video decoding.
+ * @param[in] mediacodec The handle to mediacodec
+ * @param[in] width      The width for video decoding.
+ * @param[in] height     The height for video decoding.
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -284,10 +284,10 @@ int mediacodec_set_venc_info(mediacodec_h mediacodec, int width, int height, int
 /**
  * @brief Sets the default info for the audio decoder
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
- * @param[in] samplerate  The samplerate for audio decoding.
- * @param[in] channel  The channels for audio decoding.
 * @param[in] bit  The bits resolution for audio decoding.
+ * @param[in] mediacodec The handle to mediacodec
+ * @param[in] samplerate The samplerate for audio decoding.
+ * @param[in] channel    The channels for audio decoding.
* @param[in] bit        The bits resolution for audio decoding.
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -297,12 +297,12 @@ int mediacodec_set_venc_info(mediacodec_h mediacodec, int width, int height, int
 int mediacodec_set_adec_info(mediacodec_h mediacodec, int samplerate, int channel, int bit);
 
 /**
- * @brief Sets the default info for the audio encdoer
+ * @brief Sets the default info for the audio encoder
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
- * @param[in] samplerate  The samplerate for audio encoding.
- * @param[in] channel  The channels for audio encoding.
- * @param[in] bit  The bits resolution for audio encoding.
+ * @param[in] mediacodec The handle to mediacodec
+ * @param[in] samplerate The samplerate for audio encoding.
+ * @param[in] channel    The channels for audio encoding.
+ * @param[in] bit        The bits resolution for audio encoding.
  * @param[in] bitrate  The bitrate for audio encoding.
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
@@ -313,9 +313,47 @@ int mediacodec_set_adec_info(mediacodec_h mediacodec, int samplerate, int channe
 int mediacodec_set_aenc_info(mediacodec_h mediacodec, int samplerate, int channel, int bit, int bitrate);
 
 /**
+ * @brief Sets the codec type and codec default info via media format.
+ * @details Sets the value via media format instead of mediacodec_set_codec(), mediacodec_set_venc_info(),
+ *          mediacodec_set_vdec_info(), mediacodec_set_aenc_info(), and mediacodec_set_adec_info().
+ * @since_tizen 4.0
+ * @remarks When using the @a format parameter from the output of the media demuxer, you can use media format via media_packet_get_format().
+ *          Otherwise, you must set the following values after creating media format.
+ *          Set the audio or video codec type via media_format_set_video_mime() or media_format_set_audio_mime().
+ *          For video decoding, width, height must be set via media_format_set_video_width() and media_format_set_video_height().
+ *          For video encoding, width, height, target bitrate, and frame rate must be set via media_format_set_video_avg_bps() and media_format_set_video_frame_rate().
+ *          For audio decoding, samplerate, channel, and bit must be set via media_format_set_audio_samplerate(), media_format_set_audio_channel() and media_format_set_audio_bit().
+ *          For audio encoding, samplerate, channel, bit, and bitrate must be set via media_format_set_audio_avg_bps().\n
+ *          If this codec is to be used as a decoder, pass the #MEDIACODEC_DECODER flag.
+ *          If this codec is to be used as an encoder, pass the #MEDIACODEC_ENCODER flag.\n
+ *          The software codec is used as default setting (#MEDIACODEC_SUPPORT_TYPE_SW) if user doesn't set hardware flag.
+ *          If you wants to use h/w decoder, you needs to pass the #MEDIACODEC_DECODER | #MEDIACODEC_SUPPORT_TYPE_HW.
+ * @param[in] mediacodec The mediacodec handle
+ * @param[in] format     The #media_format_h of input data
+ * @param[in] flags      The encoding/decoding scheme,
+ *                       values of #mediacodec_support_type_e combined with bitwise 'or'
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MEDIACODEC_ERROR_NONE Successful
+ * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIACODEC_ERROR_CODEC_NOT_FOUND Unsupported codec
+ * @pre The media format has been created and the required values for configuration have been set.
+ * @see media_format_set_video_mime()
+ * @see media_format_set_audio_mime()
+ * @see media_format_set_video_width()
+ * @see media_format_set_video_height()
+ * @see media_format_set_video_avg_bps()
+ * @see media_format_set_video_frame_rate()
+ * @see media_format_set_audio_channel()
+ * @see media_format_set_audio_samplerate()
+ * @see media_format_set_audio_bit()
+ * @see media_format_set_audio_avg_bps()
+ */
+int mediacodec_configure_from_media_format(mediacodec_h mediacodec, media_format_h format, int flags);
+
+/**
  * @brief Prepares @a mediacodec for encoding/decoding.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
+ * @param[in] mediacodec The handle to mediacodec
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -330,7 +368,7 @@ int mediacodec_prepare(mediacodec_h mediacodec);
 /**
  * @brief Unprepares @a mediacodec for encoding/decoding.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
+ * @param[in] mediacodec The handle to mediacodec
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -341,10 +379,10 @@ int mediacodec_unprepare(mediacodec_h mediacodec);
 
 /**
  * @brief Decodes/Encodes a packet. The function passed undecoded/unencoded packet to the input queue and decode/encode a
- *          frame sequentially.
+ *        frame sequentially.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
- * @param[in] inbuf  The current input format for the decoder/encoder
+ * @param[in] mediacodec The handle to mediacodec
+ * @param[in] inbuf      The current input format for the decoder/encoder
  * @param[in] timeOutUs  The timeout in microseconds. \n
  *                       The input buffer wait up to "timeOutUs" microseconds.
  * @return @c 0 on success, otherwise a negative error value
@@ -359,9 +397,9 @@ int mediacodec_process_input(mediacodec_h mediacodec, media_packet_h inbuf, uint
 /**
  * @brief Gets the decoded or encoded packet from the output queue.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
- * @param[out] outbuf  The current output of the decoder/encoder. this function passed decoded/encoded frame to output
- *                    queue.
+ * @param[in] mediacodec The handle to mediacodec
+ * @param[out] outbuf    The current output of the decoder/encoder.
+ *                       this function passed decoded/encoded frame to output queue.
  * @param[in] timeOutUs  The timeout in microseconds. \n
  *                       The input buffer wait up to "timeOutUs" microseconds.
  * @return @c 0 on success, otherwise a negative error value
@@ -375,7 +413,7 @@ int mediacodec_get_output(mediacodec_h mediacodec, media_packet_h *outbuf, uint6
 /**
  * @brief Flushes both input and output buffers.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
- * @param[in] mediacodec  The handle to mediacodec
+ * @param[in] mediacodec The handle to mediacodec
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -385,8 +423,8 @@ int mediacodec_flush_buffers(mediacodec_h mediacodec);
 /**
  * @brief set empty buffer callback the media codec for process, asynchronously.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
- * @param[in] callback  The callback function to register
+ * @param[in] mediacodec The handle to mediacodec
+ * @param[in] callback   The callback function to register
  * @param[in] user_data  The user data to be passed to the callback function
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
@@ -401,7 +439,7 @@ int mediacodec_set_input_buffer_used_cb(mediacodec_h mediacodec, mediacodec_inpu
 /**
  * @brief unset input buffer used callback the media codec for process, asynchronously.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
+ * @param[in] mediacodec The handle to mediacodec
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -412,8 +450,8 @@ int mediacodec_unset_input_buffer_used_cb(mediacodec_h mediacodec);
 /**
  * @brief set output buffer available callback the media codec for process, asynchronously.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
- * @param[in] callback  The callback function to register
+ * @param[in] mediacodec The handle to mediacodec
+ * @param[in] callback   The callback function to register
  * @param[in] user_data  The user data to be passed to the callback function
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
@@ -428,7 +466,7 @@ int mediacodec_set_output_buffer_available_cb(mediacodec_h mediacodec, mediacode
 /**
  * @brief unset output buffer available callback the media codec for process, asynchronously.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
+ * @param[in] mediacodec The handle to mediacodec
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -439,8 +477,8 @@ int mediacodec_unset_output_buffer_available_cb(mediacodec_h mediacodec);
 /**
  * @brief set error callback the media codec for process, asynchronously.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
- * @param[in] callback  The callback function to register
+ * @param[in] mediacodec The handle to mediacodec
+ * @param[in] callback   The callback function to register
  * @param[in] user_data  The user data to be passed to the callback function
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
@@ -455,7 +493,7 @@ int mediacodec_set_error_cb(mediacodec_h mediacodec, mediacodec_error_cb callbac
 /**
  * @brief unset error callback the media codec for process, asynchronously.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
+ * @param[in] mediacodec The handle to mediacodec
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -466,8 +504,8 @@ int mediacodec_unset_error_cb(mediacodec_h mediacodec);
 /**
  * @brief set eos callback the media codec for process, asynchronously.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
- * @param[in] callback  The callback function to register
+ * @param[in] mediacodec The handle to mediacodec
+ * @param[in] callback   The callback function to register
  * @param[in] user_data  The user data to be passed to the callback function
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
@@ -482,7 +520,7 @@ int mediacodec_set_eos_cb(mediacodec_h mediacodec, mediacodec_eos_cb callback, v
 /**
  * @brief unset eos callback the media codec for process, asynchronously.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] mediacodec  The handle to mediacodec
+ * @param[in] mediacodec The handle to mediacodec
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -493,8 +531,8 @@ int mediacodec_unset_eos_cb(mediacodec_h mediacodec);
 /**
  * @brief Registers a callback function to be invoked when the mediacodec needs more data or has enough data.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
- * @param[in] mediacodec  The handle to mediacodec
- * @param[in] callback  The callback function to register
+ * @param[in] mediacodec The handle to mediacodec
+ * @param[in] callback   The callback function to register
  * @param[in] user_data  The user data to be passed to the callback function
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
@@ -509,7 +547,7 @@ int mediacodec_set_buffer_status_cb(mediacodec_h mediacodec, mediacodec_buffer_s
 /**
  * @brief Unregisters the callback function.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
- * @param[in] mediacodec  The handle to mediacodec
+ * @param[in] mediacodec The handle to mediacodec
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -519,9 +557,9 @@ int mediacodec_unset_buffer_status_cb(mediacodec_h mediacodec);
 /**
  * @brief Retrieves all supported codecs by invoking callback function once for each supported codecs.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
- * @param[in] mediacodec  The handle to mediacodec
- * @param[in] callback  The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
+ * @param[in] mediacodec The handle to mediacodec
+ * @param[in] callback   The callback function to invoke
+ * @param[in] user_data  The user data to be passed to the callback function
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -532,10 +570,10 @@ int mediacodec_foreach_supported_codec(mediacodec_h mediacodec, mediacodec_suppo
 /**
  * @brief Verifies whether encoding can be performed with codec_type or not.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
- * @param[in] mediacodec  The handle to mediacodec
- * @param[in]  codec_type  The identifier of the codec type of the encoder.
- * @param[in]  encoder  Whether the encoder or decoder : (@c true = encoder, @c false = decoder).
- * @param[out]  support_type  (@c MEDIACODEC_SUPPORT_TYPE_HW = mediacodec can be performed with hardware codec, @c MEDIACODEC_SUPPORT_TYPE_SW = mediacodec can be performed with software codec)
+ * @param[in]  mediacodec   The handle to mediacodec
+ * @param[in]  codec_type   The identifier of the codec type of the encoder.
+ * @param[in]  encoder      Whether the encoder or decoder : (@c true = encoder, @c false = decoder).
+ * @param[out] support_type (@c MEDIACODEC_SUPPORT_TYPE_HW = mediacodec can be performed with hardware codec, @c MEDIACODEC_SUPPORT_TYPE_SW = mediacodec can be performed with software codec)
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
@@ -563,11 +601,11 @@ int mediacodec_get_supported_type(mediacodec_h mediacodec, mediacodec_codec_type
 /**
  * @brief Gets the media packet pool allocated for recycling media packets.
  * @details The user can get the pool allocated with the number of packets are required to be used in codecs.\n
- *             It is recomended to use media packet pool for better stability and performance.
+ *          It is recomended to use media packet pool for better stability and performance.
  * @since_tizen 3.0
  * @remarks The @a pool should be released using media_packet_pool_deallocate() and destroyed using media_packet_pool_destroy().
- * @param[in] mediacodec  The mediacodec handle
- * @param[out] pool The allocated pool handle
+ * @param[in]  mediacodec The mediacodec handle
+ * @param[out] pool       The allocated pool handle
  * @return @c 0 on success, otherwise a negative error value
  * @retval #MEDIACODEC_ERROR_NONE Successful
  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
index 30937c2..f704059 100644 (file)
@@ -253,6 +253,8 @@ int mc_set_venc_info(MMHandleType mediacodec, int width, int height, int fps, in
 int mc_set_adec_info(MMHandleType mediacodec, int samplerate, int channel, int bit);
 int mc_set_aenc_info(MMHandleType mediacodec, int samplerate, int channel, int bit,  int bitrate);
 
+int mc_configure(MMHandleType mediacodec, media_format_h format, int flags);
+
 int mc_prepare(MMHandleType mediacodec);
 int mc_unprepare(MMHandleType mediacodec);
 
index 45d9454..2d8c848 100644 (file)
@@ -253,6 +253,22 @@ int mediacodec_set_aenc_info(mediacodec_h mediacodec, int samplerate, int channe
        }
 }
 
+int mediacodec_configure_from_media_format(mediacodec_h mediacodec, media_format_h format, int flags)
+{
+       MEDIACODEC_INSTANCE_CHECK(mediacodec);
+       mediacodec_s *handle = (mediacodec_s *)mediacodec;
+       MEDIACODEC_STATE_CHECK(handle, MEDIACODEC_STATE_IDLE);
+
+       int ret = mc_configure(handle->mc_handle, format, flags);
+
+       if (ret != MEDIACODEC_ERROR_NONE) {
+               return __convert_error_code(ret, (char *)__FUNCTION__);
+       } else {
+               handle->state = MEDIACODEC_STATE_IDLE;
+               return MEDIACODEC_ERROR_NONE;
+       }
+}
+
 int mediacodec_prepare(mediacodec_h mediacodec)
 {
        MEDIACODEC_INSTANCE_CHECK(mediacodec);
index 48760d6..4edb261 100644 (file)
@@ -257,6 +257,122 @@ int mc_set_aenc_info(MMHandleType mediacodec, int samplerate, int channel, int b
        return ret;
 }
 
+int mc_configure(MMHandleType mediacodec, media_format_h format, int flags)
+{
+       int ret = MC_ERROR_NONE;
+       mc_handle_t *mc_handle = (mc_handle_t *) mediacodec;
+       int i;
+       const int codec_mask = 0xFFF0;
+       int codec_id = 0;
+       int channel = 0;
+       int samplerate = 0;
+       int bit = 0;
+       int bitrate = 0;
+       int width = 0;
+       int height = 0;
+       int fps = 0;
+       media_format_type_e type;
+       media_format_mimetype_e mimetype;
+
+       if (!mc_handle) {
+               LOGE("fail invaild param");
+               return MC_INVALID_ARG;
+       }
+
+       if (media_format_get_type(format, &type) != MEDIA_FORMAT_ERROR_NONE) {
+               LOGE("failed to retrieve type");
+               return MC_INVALID_ARG;
+       }
+
+       if (type == MEDIA_FORMAT_AUDIO) {
+               media_format_get_audio_info(format, &mimetype, &channel, &samplerate, &bit, &bitrate);
+
+               if (GET_IS_ENCODER(flags)) {
+                       if ((samplerate <= 0) || (channel <= 0) || (bit <= 0) || (bitrate <= 0)) {
+                               LOGE("invalid pram is set : samplerate : %d, channel : %d, bit : %d, bitrate : %d",
+                                       samplerate, channel, bit, bitrate);
+                               return MC_PARAM_ERROR;
+                       }
+
+                       mc_handle->info.encoder.samplerate = samplerate;
+                       mc_handle->info.encoder.channel = channel;
+                       mc_handle->info.encoder.bit = bit;
+                       mc_handle->info.encoder.bitrate = bitrate * 1000;
+               } else if (GET_IS_DECODER(flags)) {
+                       if ((samplerate <= 0) || (channel <= 0) || (bit <= 0)) {
+                               LOGE("invalid pram is set : samplerate : %d, channel : %d, bit : %d",
+                                       samplerate, channel, bit);
+                               return MC_PARAM_ERROR;
+                       }
+                       mc_handle->info.decoder.samplerate = samplerate;
+                       mc_handle->info.decoder.channel = channel;
+                       mc_handle->info.decoder.bit = bit;
+               } else {
+                       LOGE("either an encoder or a decoder must be set");
+                       return MC_PARAM_ERROR;
+               }
+       } else if (type == MEDIA_FORMAT_VIDEO) {
+               media_format_get_video_info(format, &mimetype, &width, &height, &bitrate, NULL);
+               media_format_get_video_frame_rate(format, &fps);
+
+               if (GET_IS_ENCODER(flags)) {
+                       if ((width <= 0) || (height <= 0) || (bitrate <= 0) || (fps <= 0)) {
+                               LOGE("invalid pram is set : width : %d, height : %d, bitrate : %d, fps : %d",
+                                       width, height, bitrate, fps);
+                               return MC_PARAM_ERROR;
+                       }
+
+                       mc_handle->info.encoder.width = width;
+                       mc_handle->info.encoder.height = height;
+                       mc_handle->info.encoder.fps = fps;
+                       mc_handle->info.encoder.bitrate = bitrate * 1000;
+               } else if (GET_IS_DECODER(flags)) {
+                       if ((width <= 0) || (height <= 0)) {
+                               LOGE("invalid pram is set : width : %d, height : %d",
+                                       width, height);
+                               return MC_PARAM_ERROR;
+                       }
+
+                       mc_handle->info.decoder.width = width;
+                       mc_handle->info.decoder.height = height;
+               } else {
+                       LOGE("either an encoder or a decoder must be set");
+                       return MC_PARAM_ERROR;
+               }
+       } else {
+               LOGE("invalid format type is set");
+               return MC_PARAM_ERROR;
+       }
+
+       if (!GET_IS_HW(flags) && !GET_IS_SW(flags))
+               flags |= MEDIACODEC_SUPPORT_TYPE_SW;
+
+       codec_id = mimetype & codec_mask;
+
+       for (i = 0; i < mc_handle->ini->num_supported_codecs; i++) {
+               if ((codec_id == spec_emul[i].codec_id) && (flags == spec_emul[i].codec_type))
+                       break;
+       }
+       LOGD("support_list : %d, i : %d", mc_handle->ini->num_supported_codecs, i);
+
+       if (i == mc_handle->ini->num_supported_codecs)
+               return MC_CODEC_NOT_FOUND;
+
+       mc_handle->port_type = spec_emul[i].port_type;
+
+       mc_handle->is_encoder = GET_IS_ENCODER(flags) ? 1 : 0;
+       mc_handle->is_hw = GET_IS_HW(flags) ? 1 : 0;
+       mc_handle->codec_id = codec_id;
+       mc_handle->is_video = CHECK_BIT(codec_id, 13);
+
+       mc_handle->is_prepared = true;
+
+       LOGD("encoder : %d, hardware : %d, codec_id : %x, video : %d",
+                       mc_handle->is_encoder, mc_handle->is_hw, mc_handle->codec_id, mc_handle->is_video);
+
+       return ret;
+}
+
 int mc_prepare(MMHandleType mediacodec)
 {
        int ret = MC_ERROR_NONE;
index b0e0bbd..505dede 100644 (file)
@@ -747,7 +747,7 @@ void mp3dec_extractor(App *app, guint8 **data, int *size, gboolean *have_frame,
  app->offset += *size;
  }
  */
-int  _configure(App *app, int codecid, int flag, gboolean *hardware)
+int  _configure(App *app, int codecid, int flag, gboolean *hardware, media_format_mimetype_e *codec_mime)
 {
        gboolean encoder;
        media_format_mimetype_e mime = 0;
@@ -760,6 +760,7 @@ int  _configure(App *app, int codecid, int flag, gboolean *hardware)
                if (encoder) {
                        extractor = yuv_extractor;
                        mime = *hardware ? MEDIA_FORMAT_NV12 : MEDIA_FORMAT_I420;
+                       *codec_mime = MEDIA_FORMAT_H264_SP;
                } else {
                        extractor = h264_extractor;
                        mime = MEDIA_FORMAT_H264_SP;
@@ -769,6 +770,7 @@ int  _configure(App *app, int codecid, int flag, gboolean *hardware)
                if (encoder) {
                        extractor = yuv_extractor;
                        mime = *hardware ? MEDIA_FORMAT_NV12 : MEDIA_FORMAT_I420;
+                       *codec_mime = MEDIA_FORMAT_MPEG4_SP;
                } else {
                        extractor = mpeg4_extractor;
                        mime = MEDIA_FORMAT_MPEG4_SP;
@@ -778,15 +780,17 @@ int  _configure(App *app, int codecid, int flag, gboolean *hardware)
                if (encoder) {
                        extractor = yuv_extractor;
                        mime = *hardware ? MEDIA_FORMAT_NV12 : MEDIA_FORMAT_I420;
+                       *codec_mime = MEDIA_FORMAT_H263;
                } else {
                        extractor = h263_extractor;
-                       mime = MEDIA_FORMAT_H263P;
+                       mime = MEDIA_FORMAT_H263;
                }
                break;
        case MEDIACODEC_AAC:
                if (encoder) {
                        extractor = aacenc_extractor;
                        mime = MEDIA_FORMAT_PCM_F32LE;  /* FIXME need to check according to verdor */
+                       *codec_mime = MEDIA_FORMAT_AAC;
                } else {
                        extractor = aacdec_extractor;
                        mime = MEDIA_FORMAT_AAC;
@@ -796,6 +800,7 @@ int  _configure(App *app, int codecid, int flag, gboolean *hardware)
                if (encoder) {
                        extractor = aacenc_extractor;
                        mime = MEDIA_FORMAT_PCM_F32LE;  /* FIXME need to check according to verdor */
+                       *codec_mime = MEDIA_FORMAT_AAC_HE;
                }
                break;
        case MEDIACODEC_AAC_HE_PS:
@@ -1366,6 +1371,8 @@ gboolean  _foreach_cb(mediacodec_codec_type_e codec_type, void *user_data)
 void _mediacodec_prepare(App *app, gboolean frame_all)
 {
        int ret;
+       media_format_mimetype_e codec_mime;
+       media_format_h codec_format;
 
        g_print("supported codec lists -internal-\n");
        mediacodec_foreach_supported_codec_static((mediacodec_supported_codec_cb)_foreach_cb, app);
@@ -1376,47 +1383,74 @@ void _mediacodec_prepare(App *app, gboolean frame_all)
                g_print("mediacodec_create  failed\n");
                return;
        }
-
+#if 0
        /* set codec */
        ret = mediacodec_set_codec(app->mc_handle[0], app->codecid, app->flag);
        if (ret  != MEDIACODEC_ERROR_NONE) {
                g_print("mediacodec_set_codec failed\n");
                return;
        }
-
+#endif
        /* get mime and link to each codec parser */
-       app->mime = _configure(app, app->codecid, app->flag, &app->hardware);
+       app->mime = _configure(app, app->codecid, app->flag, &app->hardware, &codec_mime);
 
        /* set codec info */
        ret = media_format_create(&fmt);
 
        switch (app->type) {
        case VIDEO_DEC:
-               ret = mediacodec_set_vdec_info(app->mc_handle[0], app->width, app->height);
                media_format_set_video_mime(fmt, app->mime);
                media_format_set_video_width(fmt, app->width);
                media_format_set_video_height(fmt, app->height);
+
+               ret = mediacodec_configure_from_media_format(app->mc_handle[0], fmt, app->flag);
+               if (ret  != MEDIACODEC_ERROR_NONE)
+                       g_print("mediacodec_configure failed\n");
                break;
        case VIDEO_ENC:
-               ret = mediacodec_set_venc_info(app->mc_handle[0], app->width, app->height, app->fps, app->target_bits);
                media_format_set_video_mime(fmt, app->mime);
                media_format_set_video_width(fmt, app->width);
                media_format_set_video_height(fmt, app->height);
                media_format_set_video_avg_bps(fmt, app->target_bits);
+
+               media_format_create(&codec_format);
+               media_format_set_video_mime(codec_format, codec_mime);
+               media_format_set_video_width(codec_format, app->width);
+               media_format_set_video_height(codec_format, app->height);
+               media_format_set_video_avg_bps(codec_format, app->target_bits);
+               media_format_set_video_frame_rate(codec_format, app->fps);
+
+               ret = mediacodec_configure_from_media_format(app->mc_handle[0], codec_format, app->flag);
+               if (ret  != MEDIACODEC_ERROR_NONE)
+                       g_print("mediacodec_configure failed\n");
+               media_format_unref(codec_format);
                break;
        case AUDIO_DEC:
-               ret = mediacodec_set_adec_info(app->mc_handle[0], app->samplerate, app->channel, app->bit);
                media_format_set_audio_mime(fmt, app->mime);
                media_format_set_audio_channel(fmt, app->channel);
                media_format_set_audio_samplerate(fmt, app->samplerate);
                media_format_set_audio_bit(fmt, app->bit);
+
+               ret = mediacodec_configure_from_media_format(app->mc_handle[0], fmt, app->flag);
+               if (ret  != MEDIACODEC_ERROR_NONE)
+                       g_print("mediacodec_configure failed\n");
                break;
        case AUDIO_ENC:
-               ret = mediacodec_set_aenc_info(app->mc_handle[0], app->samplerate, app->channel, app->bit, app->bitrate);
                media_format_set_audio_mime(fmt, app->mime);
                media_format_set_audio_channel(fmt, app->channel);
                media_format_set_audio_samplerate(fmt, app->samplerate);
                media_format_set_audio_bit(fmt, app->bit);
+
+               media_format_create(&codec_format);
+               media_format_set_audio_mime(codec_format, codec_mime);
+               media_format_set_audio_channel(codec_format, app->channel);
+               media_format_set_audio_samplerate(codec_format, app->samplerate);
+               media_format_set_audio_bit(codec_format, app->bit);
+
+               ret = mediacodec_configure_from_media_format(app->mc_handle[0], codec_format, app->flag);
+               if (ret  != MEDIACODEC_ERROR_NONE)
+                       g_print("mediacodec_set_configure failed\n");
+               media_format_unref(codec_format);
                break;
        default:
                g_print("invaild type\n");