Changed the processing of mp3 _options in mp3 writer with regard to bit_rate and quality to comply with LAME, also changed the pjsua_recorder_create() parameter to allow specifying mp3 options in one of the parameter

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@785 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjmedia/include/pjmedia/mp3_port.h b/pjmedia/include/pjmedia/mp3_port.h
index 4d980b9..279ab1a 100644
--- a/pjmedia/include/pjmedia/mp3_port.h
+++ b/pjmedia/include/pjmedia/mp3_port.h
@@ -59,13 +59,21 @@
  */
 typedef struct pjmedia_mp3_encoder_option
 {
-    /** Specify whether variable bit rate should be used (say Yes!).	    */
+    /** Specify whether variable bit rate should be used. Variable bitrate
+     *  would normally produce better quality at the expense of probably
+     *  larger file.
+     */
     pj_bool_t	vbr;
 
-    /** Target bitrate, in bps. If zero, bitrate will be  calculated.	    */
+    /** Target bitrate, in bps. For VBR, if the bitrate is specified, then 
+     *  the encoder will ignore the quality settings and instead will try to 
+     *  limit the bitrate to the desired value in this setting.
+     */
     unsigned	bit_rate;
 
-    /** Encoding quality, 0-9, with 0 is the highest. 			    */
+    /** Encoding quality, 0-9, with 0 is the highest quality. For VBR, the 
+     *  quality setting will only take effect when bit_rate setting is zero.
+     */
     unsigned	quality;
 
 } pjmedia_mp3_encoder_option;
diff --git a/pjmedia/src/pjmedia/mp3_writer.c b/pjmedia/src/pjmedia/mp3_writer.c
index 5506f52..74098ff 100644
--- a/pjmedia/src/pjmedia/mp3_writer.c
+++ b/pjmedia/src/pjmedia/mp3_writer.c
@@ -199,7 +199,7 @@
     } else {
 	LConfig.format.LHV1.nVbrMethod = VBR_METHOD_DEFAULT;
 	LConfig.format.LHV1.bWriteVBRHeader = 1;
-	//LConfig.format.LHV1.dwVbrAbr_bps = fport->mp3_option.bit_rate;
+	LConfig.format.LHV1.dwVbrAbr_bps = fport->mp3_option.bit_rate;
 	LConfig.format.LHV1.bEnableVBR = 1;
     }
 
@@ -294,8 +294,8 @@
 	fport->mp3_option.vbr = PJ_TRUE;
     }
 
-    /* Calculate bitrate if it's not specified */
-    if (fport->mp3_option.bit_rate == 0) 
+    /* Calculate bitrate if it's not specified, only if it's not VBR. */
+    if (fport->mp3_option.bit_rate == 0 && !fport->mp3_option.vbr) 
 	fport->mp3_option.bit_rate = sampling_rate * channel_count;
 
     /* Set default quality if it's not specified */
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h
index 8eeceed..efdf9f4 100644
--- a/pjsip/include/pjsua-lib/pjsua.h
+++ b/pjsip/include/pjsua-lib/pjsua.h
@@ -2529,27 +2529,32 @@
 
 /**
  * Create a file recorder, and automatically connect this recorder to
- * the conference bridge.
+ * the conference bridge. The recorder currently supports recording WAV file,
+ * and on Windows, MP3 file. The type of the recorder to use is determined
+ * by the extension of the file (e.g. ".wav" or ".mp3").
  *
  * @param filename	Output file name. The function will determine the
  *			default format to be used based on the file extension.
  *			Currently ".wav" is supported on all platforms, and
  *			also ".mp3" is support on Windows.
- * @param file_format	This option is obsolete.
- * @param encoding	Optionally specify the encoding to be applied to the
- *			file. By default (if NULL is specified), the encoding
- *			is determined from the file extension (i.e. 16bit PCM
- *			is used for the WAV files).
- * @param max_size	Maximum file size. Specify -1 to remove size
- *			limitation.
+ * @param enc_type	Optionally specify the type of encoder to be used to
+ *			compress the media, if the file can support different
+ *			encodings. This value must be zero for now.
+ * @param enc_param	Optionally specify codec specific parameter to be 
+ *			passed to the file writer. For .MP3 recorder, this
+ *			can point to pjmedia_mp3_encoder_option structure to
+ *			specify additional settings for the .mp3 recorder.
+ *			For .WAV recorder, this value must be NULL.
+ * @param max_size	Maximum file size. Specify zero or -1 to remove size
+ *			limitation. This value must be zero or -1 for now.
  * @param options	Optional options.
  * @param p_id		Pointer to receive the recorder instance.
  *
  * @return		PJ_SUCCESS on success, or the appropriate error code.
  */
 PJ_DECL(pj_status_t) pjsua_recorder_create(const pj_str_t *filename,
-					   unsigned file_format,
-					   const pj_str_t *encoding,
+					   unsigned enc_type,
+					   void *enc_param,
 					   pj_ssize_t max_size,
 					   unsigned options,
 					   pjsua_recorder_id *p_id);
diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c
index c94265d..b040ff8 100644
--- a/pjsip/src/pjsua-lib/pjsua_media.c
+++ b/pjsip/src/pjsua-lib/pjsua_media.c
@@ -796,8 +796,8 @@
  * the conference bridge.
  */
 PJ_DEF(pj_status_t) pjsua_recorder_create( const pj_str_t *filename,
-					   unsigned file_format,
-					   const pj_str_t *encoding,
+					   unsigned enc_type,
+					   void *enc_param,
 					   pj_ssize_t max_size,
 					   unsigned options,
 					   pjsua_recorder_id *p_id)
@@ -811,6 +811,7 @@
     unsigned slot, file_id;
     char path[128];
     pj_str_t ext;
+    int file_format;
     pjmedia_port *port;
     pj_status_t status;
 
@@ -820,11 +821,8 @@
     /* Don't support max_size at present */
     PJ_ASSERT_RETURN(max_size == 0 || max_size == -1, PJ_EINVAL);
 
-    /* Don't support file format at present */
-    PJ_ASSERT_RETURN(file_format == 0, PJ_EINVAL);
-
-    /* Don't support encoding at present */
-    PJ_ASSERT_RETURN(encoding == NULL, PJ_EINVAL);
+    /* Don't support encoding type at present */
+    PJ_ASSERT_RETURN(enc_type == 0, PJ_EINVAL);
 
     if (pjsua_var.rec_cnt >= PJ_ARRAY_SIZE(pjsua_var.recorder))
 	return PJ_ETOOMANY;
@@ -874,7 +872,7 @@
 						pjsua_var.mconf_cfg.channel_count,
 						pjsua_var.mconf_cfg.samples_per_frame,
 						pjsua_var.mconf_cfg.bits_per_sample,
-						NULL, &port);
+						enc_param, &port);
     } else {
 	port = NULL;
 	status = PJ_ENOTSUP;