RDK Documentation (Open Sourced RDK Components)
btrCore_avMedia.c
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 /*
20  * btrCore_avMedia.c
21  * Implementation of Audio Video & Media finctionalities of Bluetooth
22  */
23 
24 /* System Headers */
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <sched.h>
28 
29 #include <glib.h>
30 
31 /* External Library Headers */
32 //TODO: Remove all direct references to bluetooth headers
33 #if defined(USE_BLUEZ5)
34 #include <bluetooth/bluetooth.h>
35 #endif
36 #include <bluetooth/audio/a2dp-codecs.h>
37 #if defined(USE_BLUEZ4)
38 #include <bluetooth/audio/ipc.h>
39 #endif
40 
41 /* Interface lib Headers */
42 #include "btrCore_logger.h"
43 
44 /* Local Headers */
45 #include "btrCore_avMedia.h"
46 
47 #include "btrCore_bt_ifce.h"
48 
49 // a2dp codec macros forward compatibility
50 #ifndef MIN_BITPOOL
51 #define MIN_BITPOOL SBC_MIN_BITPOOL
52 #endif
53 #ifndef MAX_BITPOOL
54 #define MAX_BITPOOL SBC_MAX_BITPOOL
55 #endif
56 
57 //#define AAC_SUPPORTED
58 
59 
60 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
61 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
62 
63 
64 #if defined(USE_BLUEZ4)
65 
66 /* SBC Definitions */
67 #define BTR_SBC_CHANNEL_MODE_MONO BT_A2DP_CHANNEL_MODE_MONO
68 #define BTR_SBC_CHANNEL_MODE_DUAL_CHANNEL BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL
69 #define BTR_SBC_CHANNEL_MODE_STEREO BT_A2DP_CHANNEL_MODE_STEREO
70 #define BTR_SBC_CHANNEL_MODE_JOINT_STEREO BT_A2DP_CHANNEL_MODE_JOINT_STEREO
71 
72 #define BTR_SBC_SAMPLING_FREQ_16000 BT_SBC_SAMPLING_FREQ_16000
73 #define BTR_SBC_SAMPLING_FREQ_32000 BT_SBC_SAMPLING_FREQ_32000
74 #define BTR_SBC_SAMPLING_FREQ_44100 BT_SBC_SAMPLING_FREQ_44100
75 #define BTR_SBC_SAMPLING_FREQ_48000 BT_SBC_SAMPLING_FREQ_48000
76 
77 #define BTR_SBC_ALLOCATION_SNR BT_A2DP_ALLOCATION_SNR
78 #define BTR_SBC_ALLOCATION_LOUDNESS BT_A2DP_ALLOCATION_LOUDNESS
79 
80 #define BTR_SBC_SUBBANDS_4 BT_A2DP_SUBBANDS_4
81 #define BTR_SBC_SUBBANDS_8 BT_A2DP_SUBBANDS_8
82 
83 #define BTR_SBC_BLOCK_LENGTH_4 BT_A2DP_BLOCK_LENGTH_4
84 #define BTR_SBC_BLOCK_LENGTH_8 BT_A2DP_BLOCK_LENGTH_8
85 #define BTR_SBC_BLOCK_LENGTH_12 BT_A2DP_BLOCK_LENGTH_12
86 
87 #define BTR_SBC_BLOCK_LENGTH_16 BT_A2DP_BLOCK_LENGTH_16
88 
89 #elif defined(USE_BLUEZ5)
90 
91 /* SBC Definitions */
92 #define BTR_SBC_CHANNEL_MODE_MONO SBC_CHANNEL_MODE_MONO
93 #define BTR_SBC_CHANNEL_MODE_DUAL_CHANNEL SBC_CHANNEL_MODE_DUAL_CHANNEL
94 #define BTR_SBC_CHANNEL_MODE_STEREO SBC_CHANNEL_MODE_STEREO
95 #define BTR_SBC_CHANNEL_MODE_JOINT_STEREO SBC_CHANNEL_MODE_JOINT_STEREO
96 
97 #define BTR_SBC_SAMPLING_FREQ_16000 SBC_SAMPLING_FREQ_16000
98 #define BTR_SBC_SAMPLING_FREQ_32000 SBC_SAMPLING_FREQ_32000
99 #define BTR_SBC_SAMPLING_FREQ_44100 SBC_SAMPLING_FREQ_44100
100 #define BTR_SBC_SAMPLING_FREQ_48000 SBC_SAMPLING_FREQ_48000
101 
102 #define BTR_SBC_ALLOCATION_SNR SBC_ALLOCATION_SNR
103 #define BTR_SBC_ALLOCATION_LOUDNESS SBC_ALLOCATION_LOUDNESS
104 
105 #define BTR_SBC_SUBBANDS_4 SBC_SUBBANDS_4
106 #define BTR_SBC_SUBBANDS_8 SBC_SUBBANDS_8
107 
108 #define BTR_SBC_BLOCK_LENGTH_4 SBC_BLOCK_LENGTH_4
109 #define BTR_SBC_BLOCK_LENGTH_8 SBC_BLOCK_LENGTH_8
110 #define BTR_SBC_BLOCK_LENGTH_12 SBC_BLOCK_LENGTH_12
111 #define BTR_SBC_BLOCK_LENGTH_16 SBC_BLOCK_LENGTH_16
112 
113 #ifndef MIN_BITPOOL
114 #define MIN_BITPOOL SBC_MIN_BITPOOL
115 #endif
116 
117 #ifndef MAX_BITPOOL
118 #define MAX_BITPOOL SBC_MAX_BITPOOL
119 #endif
120 
121 #if defined(AAC_SUPPORTED)
122 
123 /* MPEG Definitions */
124 #define BTR_MPEG_CHANNEL_MODE_MONO MPEG_CHANNEL_MODE_MONO
125 #define BTR_MPEG_CHANNEL_MODE_DUAL_CHANNEL MPEG_CHANNEL_MODE_DUAL_CHANNEL
126 #define BTR_MPEG_CHANNEL_MODE_STEREO MPEG_CHANNEL_MODE_STEREO
127 #define BTR_MPEG_CHANNEL_MODE_JOINT_STEREO MPEG_CHANNEL_MODE_JOINT_STEREO
128 
129 #define BTR_MPEG_LAYER_MP1 MPEG_LAYER_MP1
130 #define BTR_MPEG_LAYER_MP2 MPEG_LAYER_MP2
131 #define BTR_MPEG_LAYER_MP3 MPEG_LAYER_MP3
132 
133 #define BTR_MPEG_SAMPLING_FREQ_16000 MPEG_SAMPLING_FREQ_16000
134 #define BTR_MPEG_SAMPLING_FREQ_22050 MPEG_SAMPLING_FREQ_22050
135 #define BTR_MPEG_SAMPLING_FREQ_24000 MPEG_SAMPLING_FREQ_24000
136 #define BTR_MPEG_SAMPLING_FREQ_32000 MPEG_SAMPLING_FREQ_32000
137 #define BTR_MPEG_SAMPLING_FREQ_44100 MPEG_SAMPLING_FREQ_44100
138 #define BTR_MPEG_SAMPLING_FREQ_48000 MPEG_SAMPLING_FREQ_48000
139 
140 #define BTR_MPEG_BIT_RATE_VBR MPEG_BIT_RATE_VBR
141 #define BTR_MPEG_BIT_RATE_320000 MPEG_BIT_RATE_320000
142 #define BTR_MPEG_BIT_RATE_256000 MPEG_BIT_RATE_256000
143 #define BTR_MPEG_BIT_RATE_224000 MPEG_BIT_RATE_224000
144 #define BTR_MPEG_BIT_RATE_192000 MPEG_BIT_RATE_192000
145 #define BTR_MPEG_BIT_RATE_160000 MPEG_BIT_RATE_160000
146 #define BTR_MPEG_BIT_RATE_128000 MPEG_BIT_RATE_128000
147 #define BTR_MPEG_BIT_RATE_112000 MPEG_BIT_RATE_112000
148 #define BTR_MPEG_BIT_RATE_96000 MPEG_BIT_RATE_96000
149 #define BTR_MPEG_BIT_RATE_80000 MPEG_BIT_RATE_80000
150 #define BTR_MPEG_BIT_RATE_64000 MPEG_BIT_RATE_64000
151 #define BTR_MPEG_BIT_RATE_56000 MPEG_BIT_RATE_56000
152 #define BTR_MPEG_BIT_RATE_48000 MPEG_BIT_RATE_48000
153 #define BTR_MPEG_BIT_RATE_40000 MPEG_BIT_RATE_40000
154 #define BTR_MPEG_BIT_RATE_32000 MPEG_BIT_RATE_32000
155 #define BTR_MPEG_BIT_RATE_FREE MPEG_BIT_RATE_FREE
156 
157 /* AAC Definitions */
158 #define BTR_AAC_OT_MPEG2_AAC_LC AAC_OBJECT_TYPE_MPEG2_AAC_LC
159 #define BTR_AAC_OT_MPEG4_AAC_LC AAC_OBJECT_TYPE_MPEG4_AAC_LC
160 #define BTR_AAC_OT_MPEG4_AAC_LTP AAC_OBJECT_TYPE_MPEG4_AAC_LTP
161 #define BTR_AAC_OT_MPEG4_AAC_SCA AAC_OBJECT_TYPE_MPEG4_AAC_SCA
162 
163 #define BTR_AAC_SAMPLING_FREQ_8000 AAC_SAMPLING_FREQ_8000
164 #define BTR_AAC_SAMPLING_FREQ_11025 AAC_SAMPLING_FREQ_11025
165 #define BTR_AAC_SAMPLING_FREQ_12000 AAC_SAMPLING_FREQ_12000
166 #define BTR_AAC_SAMPLING_FREQ_16000 AAC_SAMPLING_FREQ_16000
167 #define BTR_AAC_SAMPLING_FREQ_22050 AAC_SAMPLING_FREQ_22050
168 #define BTR_AAC_SAMPLING_FREQ_24000 AAC_SAMPLING_FREQ_24000
169 #define BTR_AAC_SAMPLING_FREQ_32000 AAC_SAMPLING_FREQ_32000
170 #define BTR_AAC_SAMPLING_FREQ_44100 AAC_SAMPLING_FREQ_44100
171 #define BTR_AAC_SAMPLING_FREQ_48000 AAC_SAMPLING_FREQ_48000
172 #define BTR_AAC_SAMPLING_FREQ_64000 AAC_SAMPLING_FREQ_64000
173 #define BTR_AAC_SAMPLING_FREQ_88200 AAC_SAMPLING_FREQ_88200
174 #define BTR_AAC_SAMPLING_FREQ_96000 AAC_SAMPLING_FREQ_96000
175 
176 #define BTR_AAC_CHANNELS_1 AAC_CHANNELS_1
177 #define BTR_AAC_CHANNELS_2 AAC_CHANNELS_2
178 
179 #define BTR_AAC_SET_BITRATE AAC_SET_BITRATE
180 #define BTR_AAC_SET_FREQ AAC_SET_FREQUENCY
181 #define BTR_AAC_GET_BITRATE AAC_GET_BITRATE
182 #define BTR_AAC_GET_FREQ AAC_GET_FREQUENCY
183 
184 #endif
185 
186 #endif
187 
188 #define BTR_SBC_HIGH_BITRATE_BITPOOL 51
189 #define BTR_SBC_MED_BITRATE_BITPOOL 33
190 #define BTR_SBC_LOW_BITRATE_BITPOOL 19
191 
192 #define BTR_SBC_DEFAULT_BITRATE_BITPOOL BTR_SBC_HIGH_BITRATE_BITPOOL
193 
194 #define BTR_MEDIA_INVALID_ID 0xFFFFFFFFFFFFFFFF
195 #define BTR_MEDIA_PLAYLIST_ID 0x8000000000000000
196 #define BTR_MEDIA_BROWSER_ID 0x0
197 
198 //TODO Move to Private Header
199 typedef enum _enBTRCoreAVMTransportPathState {
200  enAVMTransportStConnected,
201  enAVMTransportStToBeConnected,
202  enAVMTransportStDisconnected
203 } enBTRCoreAVMTransportPathState;
204 
205 typedef enum _eBTRCoreAVMediaPlayerType {
206  eBTRCoreAVMPTypAudio,
207  eBTRCoreAVMPTypVideo,
208  eBTRCoreAVMPTypAudioBroadcasting,
209  eBTRCoreAVMPTypVideoBroadcasting,
210  eBTRCoreAVMPTypUnknown
211 } eBTRCoreAVMediaPlayerType;
212 
213 typedef enum _eBTRCoreAVMediaPlayerSubtype {
214  eBTRCoreAVMPSbTypAudioBook,
215  eBTRCoreAVMPSbTypPodcast,
216  eBTRCoreAVMPSbTypUnknown
217 } eBTRCoreAVMediaPlayerSubtype;
218 
219 //TODO Change to macros - store as bit infos
220 typedef enum _eBTRCoreAVMediaItemFilterAtt {
221  eBTRcoreAVMFilterAttTitle,
222  eBTRcoreAVMFilterAttArtist,
223  eBTRcoreAVMFilterAttAlbum,
224  eBTRcoreAVMFilterAttGenre,
225  eBTRcoreAVMFilterAttNumberOfTracks,
226  eBTRcoreAVMFilterAttTrackNumber,
227  eBTRcoreAVMFilterAttDuration,
228  eBTRcoreAVMFilterAttUnknown
229 } eBTRCoreAVMediaItemFilterAtt;
230 
232  unsigned int ui32AVMediaFolderFilterStartIndex;
233  unsigned int ui32AVMediaFolderFilterEndIndex;
234  unsigned char mediaItemFilterAttFlag;
236 
237 typedef struct _stBTRCoreAVMediaItem {
238  void* pvAVMediaParentItem;
239  unsigned char bIsMediaItemPlayable;
240  char pcAVMediaItemPath[BTRCORE_MAX_STR_LEN];
241  char pcAVMediaItemName[BTRCORE_MAX_STR_LEN];
242  unsigned int ui32AVMediaNumberOfItems; /* thing about populated items count */
243  tBTRCoreAVMediaElementId ui32AVMediaItemId;
244  eBTRCoreAVMElementType eMediaItemType;
245 
246  union {
247  struct _stBTRCoreAVMediaItem** pstAVMediaSubItems;
248  stBTRCoreAVMediaTrackInfo mediaTrackInfo;
249  };
251 
252 typedef struct _stBTRCoreAVMediaPlayer {
253  char m_mediaPlayerName[BTRCORE_MAX_STR_LEN];
254  eBTRCoreAVMediaPlayerType eAVMediaPlayerType;
255  eBTRCoreAVMediaPlayerSubtype eAVMediaPlayerSubtype;
256  enBTRCoreAVMediaCtrl eAVMediaPlayerEqualizer;
257  enBTRCoreAVMediaCtrl eAVMediaPlayerShuffle;
258  enBTRCoreAVMediaCtrl eAVMediaPlayerRepeat;
259  enBTRCoreAVMediaCtrl eAVMediaPlayerScan;
260  unsigned int m_mediaPlayerPosition;
261  unsigned char m_mediaPlayerBrowsable;
262  unsigned char m_mediaPlayerSearchable;
263  unsigned char m_mediaTrackChanged;
264  eBTRCoreAVMediaStatusUpdate eAVMediaStatusUpdate; /* change to eAVMediaTrackStatus later */
265  stBTRCoreAVMediaTrackInfo m_mediaTrackInfo;
266  stBTRCoreAVMediaItem* m_mediaBrowserItem;
268 
269 
270 typedef struct _stBTRCoreAVMediaHdl {
271  void* btIfceHdl;
272  int iBTMediaDefSampFreqPref;
273  eBTRCoreAVMType eAVMediaTypeOut;
274  eBTRCoreAVMType eAVMediaTypeIn;
275  void* pstBTMediaConfigOut;
276  void* pstBTMediaConfigIn;
277  char* pcAVMediaTransportPathOut;
278  char* pcAVMediaTransportPathIn;
279 
280  unsigned char ui8AVMediaTransportVolume;
281  BOOLEAN bAVMediaTrVolAvrcp;
282  enBTRCoreAVMTransportPathState eAVMTState;
283 
284  char* pcAVMediaPlayerPath;
285  char* pcAVMediaControlPath;
286  unsigned char bAVMediaPlayerConnected;
287  stBTRCoreAVMediaPlayer pstAVMediaPlayer;
288 
289  stBTRCoreAVMediaItem* pstAVMediaBrowser;
290  unsigned int ui32AVMediaBrowserItemCount;
291 
292  stBTRCoreAVMediaItem* pstAVMediaPlayList;
293  unsigned int ui32AVMediaPlayListItemCount;
294 
295 
296  fPtr_BTRCore_AVMediaStatusUpdateCb fpcBBTRCoreAVMediaStatusUpdate;
297  void* pcBMediaStatusUserData;
298 
299  GThread* pMediaPollingThread;
300  void* pvThreadData;
301  eBTRCoreAVMediaStatusUpdate eAVMediaStPrev;
302  tBTRCoreAVMediaElementId SelectedaBtrAVMediaItemId;
303  stBTRCoreAVMediaTrackInfo SelectedapstBTAVMediaTrackInfo;
305 
306 
307 
309  void* apvAVMUserData;
310  const char* apcAVMDevAddress;
312 
313 /* Static Function Prototypes */
314 static uint8_t btrCore_AVMedia_GetA2DPDefaultBitpool (uint8_t au8SamplingFreq, uint8_t au8AudioChannelsMode);
315 static int btrCore_AVMedia_AllocateBrowserMemory (stBTRCoreAVMediaHdl* apstlhBTRCoreAVM, stBTRCoreAVMediaItem* apstBrowser, stBTRCoreAVMediaItem** apstBrowserNew);
316 static int btrCore_AVMedia_DeallocateBrowserMemory (stBTRCoreAVMediaHdl* apstlhBTRCoreAVM, stBTRCoreAVMediaItem** apstBrowser);
317 static int btrCore_AVMedia_DeallocateUnhandledBrowserMemory (stBTRCoreAVMediaHdl* apstlhBTRCoreAVM, const char* apcBtDevAddr, stBTRCoreAVMediaItem** apstMedItem);
318 static int btrCore_AVMedia_FindMediaItem (stBTRCoreAVMediaItem* apstBrowser, tBTRCoreAVMediaElementId aui32AVMediaItemId, stBTRCoreAVMediaItem** apstMedItem);
319 static int btrCore_AVMedia_SwitchToMediaBrowserItem (stBTRCoreAVMediaHdl* apstlhBTRCoreAVM, stBTRCoreAVMediaItem* apstAVMediaItem);
320 static eBTRCoreAVMElementType btrCore_AVMedia_MapFolderTypeToElementType (enBTMediaFolderType aeMediaFolderType);
321 
322 /* Local Op Threads Prototypes */
323 static void* btrCore_AVMedia_PlaybackPositionPolling (void* arg);
324 
325 /* Incoming Callbacks Prototypes */
326 static int btrCore_AVMedia_NegotiateMediaCb (void* apBtMediaCapsInput, void** appBtMediaCapsOutput, enBTDeviceType aenBTDeviceType, enBTMediaType aenBTMediaType, void* apUserData);
327 static int btrCore_AVMedia_TransportPathCb (const char* apBtMediaTransportPath, const char* apBtMediaUuid, void* apBtMediaCaps, enBTDeviceType aenBTDeviceType, enBTMediaType aenBTMediaType, void* apUserData);
328 static int btrCore_AVMedia_MediaPlayerPathCb (const char* apcBTMediaPlayerPath, void* apUserData);
329 static int btrCore_AVMedia_MediaStatusUpdateCb (enBTDeviceType aeBtDeviceType, stBTMediaStatusUpdate* apstBtMediaStUpdate, const char* apcBtDevAddr, void* apUserData);
330 static int btrCore_AVMedia_MediaBrowserUpdateCb (stBTMediaBrowserUpdate* apstBtMediaBrUpdate, unsigned char ucItemScope, const char* apcBtDevAddr, void* apUserData);
331 
332 
333 
334 
335 /* Static Function Definition */
336 #if 0 // if zerod for reference
337 static uint8_t
338 btrCore_AVMedia_GetA2DPDefaultBitpool (
339  uint8_t au8SamplingFreq,
340  uint8_t au8AudioChannelsMode
341 ) {
342  switch (au8SamplingFreq) {
343  case BTR_SBC_SAMPLING_FREQ_16000:
344  case BTR_SBC_SAMPLING_FREQ_32000:
345  return 53;
346 
347  case BTR_SBC_SAMPLING_FREQ_44100:
348  switch (au8AudioChannelsMode) {
349  case BTR_SBC_CHANNEL_MODE_MONO:
350  case BTR_SBC_CHANNEL_MODE_DUAL_CHANNEL:
351  return 31;
352 
353  case BTR_SBC_CHANNEL_MODE_STEREO:
354  case BTR_SBC_CHANNEL_MODE_JOINT_STEREO:
355  return 53;
356 
357  default:
358  BTRCORELOG_ERROR ("Invalid A2DP channels mode %u\n", au8AudioChannelsMode);
359  return 53;
360  }
361  case BTR_SBC_SAMPLING_FREQ_48000:
362  switch (au8AudioChannelsMode) {
363  case BTR_SBC_CHANNEL_MODE_MONO:
364  case BTR_SBC_CHANNEL_MODE_DUAL_CHANNEL:
365  return 29;
366 
367  case BTR_SBC_CHANNEL_MODE_STEREO:
368  case BTR_SBC_CHANNEL_MODE_JOINT_STEREO:
369  return 51;
370 
371  default:
372  BTRCORELOG_ERROR ("Invalid A2DP channels mode %u\n", au8AudioChannelsMode);
373  return 51;
374  }
375  default:
376  BTRCORELOG_ERROR ("Invalid Bluetooth SBC sampling freq %u\n", au8SamplingFreq);
377  return 53;
378  }
379 }
380 #else
381 static uint8_t
382 btrCore_AVMedia_GetA2DPDefaultBitpool (
383  uint8_t au8SamplingFreq,
384  uint8_t au8AudioChannelsMode
385 ) {
386  switch (au8SamplingFreq) {
387  case BTR_SBC_SAMPLING_FREQ_16000:
388  case BTR_SBC_SAMPLING_FREQ_32000:
389  return BTR_SBC_DEFAULT_BITRATE_BITPOOL;
390 
391  case BTR_SBC_SAMPLING_FREQ_44100:
392  switch (au8AudioChannelsMode) {
393  case BTR_SBC_CHANNEL_MODE_MONO:
394  case BTR_SBC_CHANNEL_MODE_DUAL_CHANNEL:
395  return 31;
396 
397  case BTR_SBC_CHANNEL_MODE_STEREO:
398  case BTR_SBC_CHANNEL_MODE_JOINT_STEREO:
399  return BTR_SBC_DEFAULT_BITRATE_BITPOOL;
400 
401  default:
402  BTRCORELOG_ERROR ("Invalid A2DP channels mode %u\n", au8AudioChannelsMode);
403  return BTR_SBC_DEFAULT_BITRATE_BITPOOL;
404  }
405  case BTR_SBC_SAMPLING_FREQ_48000:
406  switch (au8AudioChannelsMode) {
407  case BTR_SBC_CHANNEL_MODE_MONO:
408  case BTR_SBC_CHANNEL_MODE_DUAL_CHANNEL:
409  return 29;
410 
411  case BTR_SBC_CHANNEL_MODE_STEREO:
412  case BTR_SBC_CHANNEL_MODE_JOINT_STEREO:
413  return BTR_SBC_DEFAULT_BITRATE_BITPOOL;
414 
415  default:
416  BTRCORELOG_ERROR ("Invalid A2DP channels mode %u\n", au8AudioChannelsMode);
417  return BTR_SBC_DEFAULT_BITRATE_BITPOOL;
418  }
419  default:
420  BTRCORELOG_ERROR ("Invalid Bluetooth SBC sampling freq %u\n", au8SamplingFreq);
421  return BTR_SBC_DEFAULT_BITRATE_BITPOOL;
422  }
423 }
424 #endif
425 
426 static int
427 btrCore_AVMedia_AllocateBrowserMemory (
428  stBTRCoreAVMediaHdl* apstlhBTRCoreAVM,
429  stBTRCoreAVMediaItem* apstBrowser,
430  stBTRCoreAVMediaItem** apstBrowserNew
431 ) {
432  int i32BtRet = -1;
433 
434  if (!apstlhBTRCoreAVM || !apstBrowserNew) {
435  BTRCORELOG_ERROR ("Invalid Args!\n");
436  return i32BtRet;
437  }
438 
439  if (!(*apstBrowserNew = (stBTRCoreAVMediaItem*) malloc (sizeof(stBTRCoreAVMediaItem)))) {
440  BTRCORELOG_ERROR ("Memory Allocation Failed !\n");
441  return i32BtRet;
442  }
443 
444  memset (*apstBrowserNew, 0, sizeof(stBTRCoreAVMediaItem));
445 
446  if (apstBrowser) {
447  /* Do we want to re-allocate based on a fixed slab mechanism, inorder to prevent frequent alloc calls */
448  BTRCORELOG_DEBUG ("Reallocating subItem from %u to %u\n", apstBrowser->ui32AVMediaNumberOfItems, apstBrowser->ui32AVMediaNumberOfItems+1);
449  if ((apstBrowser->pstAVMediaSubItems = (stBTRCoreAVMediaItem**) realloc (apstBrowser->pstAVMediaSubItems,
450  ++apstBrowser->ui32AVMediaNumberOfItems * sizeof(stBTRCoreAVMediaItem*)))) {
451  apstBrowser->pstAVMediaSubItems[apstBrowser->ui32AVMediaNumberOfItems -1] = *apstBrowserNew;
452  i32BtRet = 0;
453  }
454  else {
455  BTRCORELOG_ERROR ("Memory Re-allocation Failed !\n");
456  }
457  }
458  else {
459  i32BtRet = 0;
460  }
461 
462  return i32BtRet;
463 }
464 
465 
466 static int
467 btrCore_AVMedia_DeallocateBrowserMemory (
468  stBTRCoreAVMediaHdl* apstlhBTRCoreAVM,
469  stBTRCoreAVMediaItem** apstBrowser
470 ) {
471  int i32BtRet = -1;
472  stBTRCoreAVMediaItem* ptr = NULL;
473 
474  if (!apstBrowser || !(*apstBrowser)) {
475  BTRCORELOG_ERROR ("Invalid Args!\n");
476  return i32BtRet;
477  }
478 
479  if ((ptr = (*apstBrowser)->pvAVMediaParentItem)) {
480  if (ptr->pstAVMediaSubItems[ptr->ui32AVMediaNumberOfItems -1]->ui32AVMediaItemId != (*apstBrowser)->ui32AVMediaItemId) {
481  memcpy (*apstBrowser, ptr->pstAVMediaSubItems[ptr->ui32AVMediaNumberOfItems -1], sizeof(stBTRCoreAVMediaItem));
482  *apstBrowser = ptr->pstAVMediaSubItems[ptr->ui32AVMediaNumberOfItems -1];
483  }
484  }
485 
486  memset (*apstBrowser, 0, sizeof(stBTRCoreAVMediaItem));
487  free ((void*)(*apstBrowser));
488 
489  if ((*apstBrowser = ptr)) {
490  BTRCORELOG_DEBUG ("Reallocating subItem from %u to %u\n", ptr->ui32AVMediaNumberOfItems, ptr->ui32AVMediaNumberOfItems-1);
491  ptr->pstAVMediaSubItems = (stBTRCoreAVMediaItem**) realloc (ptr->pstAVMediaSubItems,
492  --ptr->ui32AVMediaNumberOfItems * sizeof(stBTRCoreAVMediaItem*));
493  if (!ptr->pstAVMediaSubItems && ptr->ui32AVMediaNumberOfItems) {
494  BTRCORELOG_ERROR ("Memory Re-allocation Failed !\n");
495  }
496  else {
497  i32BtRet = 0;
498  }
499  }
500  else {
501  i32BtRet = 0;
502  }
503 
504  return i32BtRet;
505 }
506 
507 
508 static int
509 btrCore_AVMedia_DeallocateUnhandledBrowserMemory (
510  stBTRCoreAVMediaHdl* apstlhBTRCoreAVM,
511  const char* apcBtDevAddr,
512  stBTRCoreAVMediaItem** apstMedItem
513 ) {
514  unsigned int ui32ArrayIdx[10] = {0};
515  unsigned int ui8LoopIdx = 0;
516  stBTRCoreAVMediaItem* apstBrowser = NULL;
517  stBTRCoreAVMediaItem* ptr = NULL;
518 
519  if (!apstMedItem || !(*apstMedItem) || !apstlhBTRCoreAVM) {
520  /* validate apcBtDevAddr when used */
521  BTRCORELOG_ERROR ("Invalid Args!\n");
522  return -1;
523  }
524 
525  BTRCORELOG_WARN ("!!!Clearing Off unhandled AV Media Browser memory\n");
526  apstBrowser = *apstMedItem;
527 
528  while (apstBrowser) {
529 
530  if (apstBrowser->ui32AVMediaNumberOfItems) {
531  if (!apstBrowser->bIsMediaItemPlayable && apstBrowser->pstAVMediaSubItems) {
532  if (0 < apstBrowser->ui32AVMediaNumberOfItems - ui32ArrayIdx[ui8LoopIdx]) {
533  if (apstBrowser->pstAVMediaSubItems[apstBrowser->ui32AVMediaNumberOfItems -ui32ArrayIdx[ui8LoopIdx] -1]) {
534 
535  apstBrowser = (ptr = apstBrowser)->pstAVMediaSubItems[apstBrowser->ui32AVMediaNumberOfItems -ui32ArrayIdx[ui8LoopIdx] -1];
536  ptr->pstAVMediaSubItems[ptr->ui32AVMediaNumberOfItems -ui32ArrayIdx[ui8LoopIdx] -1] = NULL;
537 
538  if (!(ptr->ui32AVMediaNumberOfItems -ui32ArrayIdx[ui8LoopIdx] -1)) {
539  BTRCORELOG_DEBUG ("Freeing Media SubItem List of %s : %p (%u)\n", ptr->pcAVMediaItemName, apstBrowser, ptr->ui32AVMediaNumberOfItems);
540  free ((void*)ptr->pstAVMediaSubItems);
541  ptr->pstAVMediaSubItems = NULL;
542  ptr->ui32AVMediaNumberOfItems = 0;
543  }
544 
545  ui32ArrayIdx[++ui8LoopIdx] = 0;
546  continue;
547  }
548  }
549  }
550  }
551 
552  ptr = apstBrowser;
553  BTRCORELOG_DEBUG ("Freeing Media Item %p:%s [ID: %llu]\n", ptr, ptr->pcAVMediaItemName, ptr->ui32AVMediaItemId);
554 #if 0
555  /* NOTE: Try to get a valid apcBtDevAddr before uncommenting this block! */
556  {
557  stBTRCoreAVMediaStatusUpdate mediaStatus;
558 
559  mediaStatus.eAVMediaState = eBTRCoreAVMediaElementRemoved;
560  mediaElement->ui32AVMediaElementId = ptr->ui32BTMediaItemId;
561 
562  if (apstlhBTRCoreAVM->fpcBBTRCoreAVMediaStatusUpdate) {
563  if (apstlhBTRCoreAVM->fpcBBTRCoreAVMediaStatusUpdate(&mediaStatus, apcBtDevAddr, apstlhBTRCoreAVM->pcBMediaStatusUserData) != enBTRCoreSuccess) {
564  BTRCORELOG_ERROR ("fpcBBTRCoreAVMediaStatusUpdate - Failure !!!\n");
565  return -1;
566  }
567  }
568  }
569 #endif
570  if (ptr->bIsMediaItemPlayable) {
571  (ptr->ui32AVMediaItemId & BTR_MEDIA_PLAYLIST_ID)? apstlhBTRCoreAVM->ui32AVMediaPlayListItemCount-- : apstlhBTRCoreAVM->ui32AVMediaBrowserItemCount--;
572  }
573 
574  if (ptr == *apstMedItem) {
575  btrCore_AVMedia_DeallocateBrowserMemory (apstlhBTRCoreAVM, &ptr);
576  *apstMedItem = ptr;
577  break;
578  }
579 
580  apstBrowser = apstBrowser->pvAVMediaParentItem;
581  free ((void*)ptr);
582  ui32ArrayIdx[--ui8LoopIdx]++;
583  }
584 
585  return 0;
586 }
587 
588 
589 static int
590 btrCore_AVMedia_FindMediaItem (
591  stBTRCoreAVMediaItem* apstBrowser,
592  tBTRCoreAVMediaElementId aui32AVMediaItemId,
593  stBTRCoreAVMediaItem** apstMedItem
594 ) {
595  unsigned int ui32ArrayIdx[10] = {0};
596  unsigned int ui8LoopIdx = 0;
597 
598  if (!apstBrowser || !apstMedItem) {
599  BTRCORELOG_ERROR ("Invalid Args!\n");
600  return -1;
601  }
602 
603  *apstMedItem = NULL;
604 
605  while (apstBrowser) {
606  //BTRCORELOG_DEBUG ("Inside Folder %p:%s - %u - %d\n", apstBrowser, apstBrowser->pcAVMediaItemName, apstBrowser->ui32AVMediaNumberOfItems, apstBrowser->bIsMediaItemPlayable);
607  if (apstBrowser->ui32AVMediaNumberOfItems) {
608 
609  if (!apstBrowser->bIsMediaItemPlayable && apstBrowser->pstAVMediaSubItems) {
610  if (0 < apstBrowser->ui32AVMediaNumberOfItems - ui32ArrayIdx[ui8LoopIdx]) {
611  if (apstBrowser->pstAVMediaSubItems[apstBrowser->ui32AVMediaNumberOfItems -ui32ArrayIdx[ui8LoopIdx] -1]) {
612  apstBrowser = apstBrowser->pstAVMediaSubItems[apstBrowser->ui32AVMediaNumberOfItems -ui32ArrayIdx[ui8LoopIdx] -1];
613  ui32ArrayIdx[++ui8LoopIdx] = 0;
614  continue;
615  }
616  }
617  }
618  }
619 
620  if (apstBrowser->ui32AVMediaItemId == aui32AVMediaItemId) {
621  *apstMedItem = apstBrowser;
622  BTRCORELOG_INFO ("Media Item Found : %s [%llu] - %d\n", apstBrowser->pcAVMediaItemName, apstBrowser->ui32AVMediaItemId, apstBrowser->bIsMediaItemPlayable);
623  }
624 
625  if (ui8LoopIdx && !(*apstMedItem)) {
626  ui32ArrayIdx[--ui8LoopIdx]++;
627  apstBrowser = apstBrowser->pvAVMediaParentItem;
628  }
629  else {
630  break;
631  }
632  }
633 
634  return 0;
635 }
636 
637 
638 static int
639 btrCore_AVMedia_SwitchToMediaBrowserItem (
640  stBTRCoreAVMediaHdl* apstlhBTRCoreAVM,
641  stBTRCoreAVMediaItem* apstAVMediaItem
642 ) {
643  stBTRCoreAVMediaItem* curr = 0;
644  stBTRCoreAVMediaItem* dest = 0;
645  int i32Ret = -1;
646 
647  if (!apstlhBTRCoreAVM || !(dest=apstAVMediaItem)) {
648  BTRCORELOG_ERROR ("Invalid Args!\n");
649  return i32Ret;
650  }
651 
652  if ((curr = apstlhBTRCoreAVM->pstAVMediaBrowser)) {
653 
654  char mediaItemPath[15][BTRCORE_MAX_STR_LEN];
655  tBTRCoreAVMediaElementId comnItemId = 0;
656  short arrayIdx =-1;
657  short countIdx = 0;
658  short commnIdx = 0;
659 
660  memset (mediaItemPath, 0, 15 * BTRCORE_MAX_STR_LEN);
661 
662  comnItemId = BtrCore_BTGetCommonParentMediaItemId (curr->ui32AVMediaItemId, dest->ui32AVMediaItemId);
663 
664  /* retrive the mediaItemPaths from current browser dir to the common parent dir */
665  if (comnItemId != curr->ui32AVMediaItemId) {
666 
667  while (curr->pvAVMediaParentItem) {
668  curr = curr->pvAVMediaParentItem;
669 
670  if (comnItemId != dest->ui32AVMediaItemId || curr->ui32AVMediaItemId != comnItemId) {
671  strncpy (mediaItemPath[countIdx++], curr->pcAVMediaItemPath, BTRCORE_MAX_STR_LEN -1);
672  }
673  if (curr->ui32AVMediaItemId == comnItemId) {
674  break;
675  }
676  }
677  }
678 
679  commnIdx = countIdx;
680 
681  /* retrive the mediaItemPaths from common parent dir to destination browser dir */
682  if (comnItemId != dest->ui32AVMediaItemId) {
683 
684  while (dest->pvAVMediaParentItem) {
685  dest = dest->pvAVMediaParentItem;
686 
687  if (comnItemId != dest->ui32AVMediaItemId) {
688  strncpy (mediaItemPath[countIdx++], dest->pcAVMediaItemPath, BTRCORE_MAX_STR_LEN -1);
689  }
690  else {
691  break;
692  }
693  }
694  }
695 
696  /* Changing from current browsing location to destination browsing location */
697  while (++arrayIdx < commnIdx || (arrayIdx = --countIdx) >= commnIdx) {
698  if (BtrCore_BTChangeMediaFolder(apstlhBTRCoreAVM->btIfceHdl, apstlhBTRCoreAVM->pcAVMediaPlayerPath, mediaItemPath[arrayIdx])) {
699  BTRCORELOG_ERROR ("Failed to Change Media Folder Path %s !\n", mediaItemPath[arrayIdx]);
700  return i32Ret;
701  }
702  }
703 
704  i32Ret = 0;
705  }
706  else {
707  BTRCORELOG_ERROR ("Media Browser Error - Browser root is NULL!\n");
708  }
709 
710  return i32Ret;
711 }
712 
713 
714 static eBTRCoreAVMElementType
715 btrCore_AVMedia_MapFolderTypeToElementType (
716  enBTMediaFolderType aeMediaFolderType
717 ) {
718  eBTRCoreAVMElementType leAVMElementType;
719 
720  switch (aeMediaFolderType) {
721  case enBTMediaFldTypAlbum:
722  leAVMElementType = eBTRCoreAVMETypeAlbum;
723  break;
724  case enBTMediaFldTypArtist:
725  leAVMElementType = eBTRCoreAVMETypeArtist;
726  break;
727  case enBTMediaFldTypGenre:
728  leAVMElementType = eBTRCoreAVMETypeGenre;
729  break;
730  case enBTMediaFldTypCompilation:
731  leAVMElementType = eBTRCoreAVMETypeCompilation;
732  break;
733  case enBTMediaFldTypPlayList:
734  leAVMElementType = eBTRCoreAVMETypePlayList;
735  break;
736  case enBTMediaFldTypTrackList:
737  leAVMElementType = eBTRCoreAVMETypeTrackList;
738  break;
739  case enBTMediaFldTypTrack:
740  leAVMElementType = eBTRCoreAVMETypeTrack;
741  break;
742  default:
743  leAVMElementType = eBTRCoreAVMETypeTrackList;
744  }
745 
746  return leAVMElementType;
747 }
748 
749 
750 /* Local Op Threads */
751 static void*
752 btrCore_AVMedia_PlaybackPositionPolling (
753  void* arg
754 ) {
755  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
756  stBTRCoreAVMediaPlayer* lpstAVMediaPlayer = 0;
757  stBTRCoreAVMediaStatusUserData* pstAVMediaStUserData = NULL;
758  stBTRCoreAVMediaStatusUpdate mediaStatus;
759 
760  unsigned char isPlaying = 0;
761  unsigned int mediaPosition = 0;
762  BOOLEAN threadExit = FALSE;
763  BOOLEAN postEvent = TRUE;
764 
765  if (NULL == arg) {
766  BTRCORELOG_ERROR ("Exiting.. enBTRCoreInvalidArg!!!\n");
767  return NULL;
768  }
769 
770  BTRCORELOG_INFO ("Started AVMedia Position Polling thread successfully...\n");
771 
772  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)arg;
773  pstAVMediaStUserData = (stBTRCoreAVMediaStatusUserData*)pstlhBTRCoreAVM->pvThreadData;
774 
775  if (!pstlhBTRCoreAVM->fpcBBTRCoreAVMediaStatusUpdate || !pstlhBTRCoreAVM->pvThreadData) {
776  BTRCORELOG_ERROR("Exiting.. Invalid stBTRCoreAVMediaHdl Data!!! | fpcBBTRCoreAVMediaStatusUpdate : %p | pvThreadData : %p\n"
777  , pstlhBTRCoreAVM->fpcBBTRCoreAVMediaStatusUpdate, pstlhBTRCoreAVM->pvThreadData);
778  return NULL;
779  }
780 
781  pstAVMediaStUserData = (stBTRCoreAVMediaStatusUserData*)pstlhBTRCoreAVM->pvThreadData;
782 
783  if (!pstAVMediaStUserData->apvAVMUserData || !pstAVMediaStUserData->apcAVMDevAddress) {
784  BTRCORELOG_ERROR("Exiting.. Invalid stBTRCoreAVMediaStatusUserData Data!!! | apvAVMUserData : %p | apcAVMDevAddress : %s\n"
785  , pstAVMediaStUserData->apvAVMUserData, pstAVMediaStUserData->apcAVMDevAddress);
786  return NULL;
787  }
788 
789  lpstAVMediaPlayer = &pstlhBTRCoreAVM->pstAVMediaPlayer;
790 
791 
792  while (1) {
793 
794  if (threadExit) {
795  break;
796  }
797 
798  if (!pstlhBTRCoreAVM->pcAVMediaPlayerPath) {
799  lpstAVMediaPlayer->eAVMediaStatusUpdate = eBTRCoreAVMediaPlaybackEnded;
800  }
801 
802  if (lpstAVMediaPlayer->eAVMediaStatusUpdate == eBTRCoreAVMediaTrkStPlaying) {
803  isPlaying = 1;
804  mediaStatus.eAVMediaState = eBTRCoreAVMediaTrkStPlaying;
805  }
806  else if (lpstAVMediaPlayer->eAVMediaStatusUpdate == eBTRCoreAVMediaTrkStForwardSeek) {
807  isPlaying = 1;
808  mediaStatus.eAVMediaState = eBTRCoreAVMediaTrkStPlaying;
809  }
810  else if (lpstAVMediaPlayer->eAVMediaStatusUpdate == eBTRCoreAVMediaTrkStReverseSeek) {
811  isPlaying = 1;
812  mediaStatus.eAVMediaState = eBTRCoreAVMediaTrkStPlaying;
813  }
814  else if (lpstAVMediaPlayer->eAVMediaStatusUpdate == eBTRCoreAVMediaTrkStPaused) {
815  mediaStatus.eAVMediaState = eBTRCoreAVMediaTrkStPaused;
816  if(pstlhBTRCoreAVM->eAVMediaStPrev != eBTRCoreAVMediaTrkStPaused) {
817  isPlaying = 1;
818  }
819  }
820  else if (lpstAVMediaPlayer->eAVMediaStatusUpdate == eBTRCoreAVMediaTrkStStopped) {
821  mediaStatus.eAVMediaState = eBTRCoreAVMediaTrkStStopped;
822  }
823  else if (lpstAVMediaPlayer->eAVMediaStatusUpdate == eBTRCoreAVMediaPlaybackEnded) {
824  mediaStatus.eAVMediaState = eBTRCoreAVMediaPlaybackEnded;
825  BTRCORELOG_WARN ("Audio StreamIn Status : PlaybackEnded !!!\n");
826  isPlaying = 1;
827  threadExit = TRUE;
828  }
829  else if (lpstAVMediaPlayer->eAVMediaStatusUpdate == eBTRCoreAVMediaPlaybackError) {
830  mediaStatus.eAVMediaState = eBTRCoreAVMediaPlaybackError;
831  BTRCORELOG_ERROR ("[%s] Audio StreamIn Status : Error !!!\n", pstlhBTRCoreAVM->pcAVMediaPlayerPath);
832  }
833  else if (lpstAVMediaPlayer->eAVMediaStatusUpdate != eBTRCoreAVMediaTrkStStarted) {
834  mediaStatus.eAVMediaState = eBTRCoreAVMediaPlaybackError;
835  BTRCORELOG_ERROR ("[%s] Unknown Audio StreamIn Status : %d !!!\n", pstlhBTRCoreAVM->pcAVMediaPlayerPath, lpstAVMediaPlayer->eAVMediaStatusUpdate);
836  }
837 
838 
839  if (isPlaying) {
840 
841  if (mediaStatus.eAVMediaState != eBTRCoreAVMediaPlaybackEnded && mediaStatus.eAVMediaState != eBTRCoreAVMediaPlaybackError) {
842  if (!BtrCore_BTGetMediaPlayerProperty(pstlhBTRCoreAVM->btIfceHdl, pstlhBTRCoreAVM->pcAVMediaPlayerPath, "Position", (void*)&mediaPosition)) {
843  lpstAVMediaPlayer->m_mediaPlayerPosition = mediaPosition;
844  }
845  else {
846  BTRCORELOG_ERROR ("Failed to get MediaPlayer Position Property !!!\n");
847  }
848 
849  if (pstlhBTRCoreAVM->eAVMTState == enAVMTransportStConnected) {
850  if (lpstAVMediaPlayer->m_mediaTrackChanged) {
851  mediaStatus.eAVMediaState = eBTRCoreAVMediaTrkStStarted;
852  lpstAVMediaPlayer->m_mediaTrackChanged = 0;
853  }
854  else {
855  if(((pstlhBTRCoreAVM->eAVMediaStPrev == eBTRCoreAVMediaTrkStPlaying) || (pstlhBTRCoreAVM->eAVMediaStPrev == eBTRCoreAVMediaTrkPosition) )&&
856  (mediaStatus.eAVMediaState == eBTRCoreAVMediaTrkStPlaying)) {
857  mediaStatus.eAVMediaState = eBTRCoreAVMediaTrkPosition;
858  }
859  }
860  }
861  else {
862  if (lpstAVMediaPlayer->eAVMediaStatusUpdate == eBTRCoreAVMediaTrkStPlaying) {
863  mediaStatus.eAVMediaState = eBTRCoreAVMediaTrkStPaused;
864  }
865  }
866  }
867  else {
868  postEvent = TRUE;
869  }
870 
871 
872  mediaStatus.m_mediaPositionInfo.ui32Position = lpstAVMediaPlayer->m_mediaPlayerPosition;
873  mediaStatus.m_mediaPositionInfo.ui32Duration = lpstAVMediaPlayer->m_mediaTrackInfo.ui32Duration;
874 
875  /* post callback */
876  if (postEvent) {
877  pstlhBTRCoreAVM->fpcBBTRCoreAVMediaStatusUpdate(&mediaStatus,
878  pstAVMediaStUserData->apcAVMDevAddress,
879  pstlhBTRCoreAVM->pcBMediaStatusUserData);
880  }
881 
882  if (pstlhBTRCoreAVM->eAVMTState != enAVMTransportStConnected) {
883  postEvent = FALSE;
884  }
885  else {
886  postEvent = TRUE;
887  }
888  }
889 
890  pstlhBTRCoreAVM->eAVMediaStPrev = mediaStatus.eAVMediaState;
891 
892  if (eBTRCoreAVMediaTrkStStarted == mediaStatus.eAVMediaState || eBTRCoreAVMediaTrkStPlaying == mediaStatus.eAVMediaState || eBTRCoreAVMediaTrkPosition == mediaStatus.eAVMediaState ) {
893  sleep(1); /* polling playback position with 1 sec interval */
894  }
895  else {
896  isPlaying = 0;
897  usleep(100000); /* sleeping 1/10th of a second to check playback status */
898  }
899 
900  }
901 
902  BTRCORELOG_INFO ("Exiting MediaPosition Polling Thread...\n");
903 
904  return NULL;
905 }
906 
907 
908 //////////////////
909 // Interfaces //
910 //////////////////
911 enBTRCoreRet
913  tBTRCoreAVMediaHdl* phBTRCoreAVM,
914  void* apBtConn,
915  const char* apBtAdapter
916 ) {
917  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
918  int lBtAVMediaDelayReport = 1;
919  int lBtAVMediaASinkRegRet = -1;
920  int lBtAVMediaASrcRegRet = -1;
921  int lBtAVMediaNegotiateRet = -1;
922  int lBtAVMediaTransportPRet = -1;
923  int lBTAVMediaPlayerPRet = -1;
924  int lBTAVMediaStatusRet = -1;
925  int lBTAVMediaBrowserRet = -1;
926  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
927 
928  if (!phBTRCoreAVM || !apBtConn || !apBtAdapter) {
929  return enBTRCoreInvalidArg;
930  }
931 
932 
933  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)malloc(sizeof(stBTRCoreAVMediaHdl));
934  if (!pstlhBTRCoreAVM)
935  return enBTRCoreInitFailure;
936 
937  memset(pstlhBTRCoreAVM, 0, sizeof(stBTRCoreAVMediaHdl));
938 
939  pstlhBTRCoreAVM->pstBTMediaConfigOut = malloc(MAX(MAX(sizeof(a2dp_aac_t), sizeof(a2dp_mpeg_t)), sizeof(a2dp_sbc_t)));
940  pstlhBTRCoreAVM->pstBTMediaConfigIn = malloc(MAX(MAX(sizeof(a2dp_aac_t), sizeof(a2dp_mpeg_t)), sizeof(a2dp_sbc_t)));
941 
942  if (!pstlhBTRCoreAVM->pstBTMediaConfigOut || !pstlhBTRCoreAVM->pstBTMediaConfigIn) {
943 
944  if (pstlhBTRCoreAVM->pstBTMediaConfigIn)
945  free(pstlhBTRCoreAVM->pstBTMediaConfigIn);
946 
947  if (pstlhBTRCoreAVM->pstBTMediaConfigOut)
948  free(pstlhBTRCoreAVM->pstBTMediaConfigOut);
949 
950  free(pstlhBTRCoreAVM);
951  pstlhBTRCoreAVM = NULL;
952  return enBTRCoreInitFailure;
953  }
954 
955  pstlhBTRCoreAVM->btIfceHdl = apBtConn;
956  pstlhBTRCoreAVM->iBTMediaDefSampFreqPref = BTR_SBC_SAMPLING_FREQ_48000;
957  pstlhBTRCoreAVM->eAVMediaTypeOut = eBTRCoreAVMTypeUnknown;
958  pstlhBTRCoreAVM->eAVMediaTypeIn = eBTRCoreAVMTypeUnknown;
959  pstlhBTRCoreAVM->pcAVMediaTransportPathOut = NULL;
960  pstlhBTRCoreAVM->pcAVMediaTransportPathIn = NULL;
961  pstlhBTRCoreAVM->pcAVMediaPlayerPath = NULL;
962  pstlhBTRCoreAVM->pcAVMediaControlPath = NULL;
963  pstlhBTRCoreAVM->pvThreadData = NULL;
964  pstlhBTRCoreAVM->pcBMediaStatusUserData = NULL;
965  pstlhBTRCoreAVM->fpcBBTRCoreAVMediaStatusUpdate = NULL;
966  pstlhBTRCoreAVM->eAVMTState = enAVMTransportStDisconnected;
967  pstlhBTRCoreAVM->eAVMediaStPrev = eBTRCoreAVMediaStUnknown;
968 
969 
970  a2dp_sbc_t lstBtA2dpSbcCaps;
971  lstBtA2dpSbcCaps.channel_mode = BTR_SBC_CHANNEL_MODE_MONO | BTR_SBC_CHANNEL_MODE_DUAL_CHANNEL |
972  BTR_SBC_CHANNEL_MODE_STEREO | BTR_SBC_CHANNEL_MODE_JOINT_STEREO;
973 #if 0
974  lstBtA2dpSbcCaps.frequency = BTR_SBC_SAMPLING_FREQ_16000 | BTR_SBC_SAMPLING_FREQ_32000 |
975  BTR_SBC_SAMPLING_FREQ_44100 | BTR_SBC_SAMPLING_FREQ_48000;
976 #else
977  //TODO: Enable 44100 for A2DP Source
978  lstBtA2dpSbcCaps.frequency = BTR_SBC_SAMPLING_FREQ_16000 | BTR_SBC_SAMPLING_FREQ_32000 |
979  BTR_SBC_SAMPLING_FREQ_48000;
980 #endif
981  lstBtA2dpSbcCaps.allocation_method = BTR_SBC_ALLOCATION_SNR | BTR_SBC_ALLOCATION_LOUDNESS;
982  lstBtA2dpSbcCaps.subbands = BTR_SBC_SUBBANDS_4 | BTR_SBC_SUBBANDS_8;
983  lstBtA2dpSbcCaps.block_length = BTR_SBC_BLOCK_LENGTH_4 | BTR_SBC_BLOCK_LENGTH_8 |
984  BTR_SBC_BLOCK_LENGTH_12 | BTR_SBC_BLOCK_LENGTH_16;
985  lstBtA2dpSbcCaps.min_bitpool = MIN_BITPOOL;
986  lstBtA2dpSbcCaps.max_bitpool = MAX_BITPOOL;
987 
988 
989  memcpy(pstlhBTRCoreAVM->pstBTMediaConfigOut, &lstBtA2dpSbcCaps, sizeof(a2dp_sbc_t));
990  lBtAVMediaASinkRegRet = BtrCore_BTRegisterMedia(apBtConn,
991  apBtAdapter,
992  enBTDevAudioSink,
993  enBTMediaTypeSBC,
995  (void*)&lstBtA2dpSbcCaps,
996  sizeof(lstBtA2dpSbcCaps),
997  lBtAVMediaDelayReport);
998 
999 #if 1
1000  lstBtA2dpSbcCaps.frequency |= BTR_SBC_SAMPLING_FREQ_44100;
1001 #endif
1002 
1003  memcpy(pstlhBTRCoreAVM->pstBTMediaConfigIn, &lstBtA2dpSbcCaps, sizeof(a2dp_sbc_t));
1004  lBtAVMediaASrcRegRet = BtrCore_BTRegisterMedia(apBtConn,
1005  apBtAdapter,
1006  enBTDevAudioSource,
1007  enBTMediaTypeSBC,
1009  (void*)&lstBtA2dpSbcCaps,
1010  sizeof(lstBtA2dpSbcCaps),
1011  lBtAVMediaDelayReport);
1012 
1013 #if defined(AAC_SUPPORTED)
1014  a2dp_aac_t lstBtA2dpAacCaps;
1015  lstBtA2dpAacCaps.object_type = BTR_AAC_OT_MPEG2_AAC_LC | BTR_AAC_OT_MPEG4_AAC_LC |
1016  BTR_AAC_OT_MPEG4_AAC_LTP | BTR_AAC_OT_MPEG4_AAC_SCA;
1017  lstBtA2dpAacCaps.channels = BTR_AAC_CHANNELS_1 | BTR_AAC_CHANNELS_2;
1018  lstBtA2dpAacCaps.rfa = 0x3;
1019  lstBtA2dpAacCaps.vbr = 1;
1020 
1021  BTR_AAC_SET_FREQ (lstBtA2dpAacCaps,(BTR_AAC_SAMPLING_FREQ_8000 | BTR_AAC_SAMPLING_FREQ_11025 | BTR_AAC_SAMPLING_FREQ_12000 |
1022  BTR_AAC_SAMPLING_FREQ_16000 | BTR_AAC_SAMPLING_FREQ_22050 | BTR_AAC_SAMPLING_FREQ_24000 |
1023  BTR_AAC_SAMPLING_FREQ_32000 | BTR_AAC_SAMPLING_FREQ_44100 | BTR_AAC_SAMPLING_FREQ_48000 |
1024  BTR_AAC_SAMPLING_FREQ_64000 | BTR_AAC_SAMPLING_FREQ_88200 | BTR_AAC_SAMPLING_FREQ_96000));
1025 
1026  BTR_AAC_SET_BITRATE (lstBtA2dpAacCaps,(BTR_MPEG_BIT_RATE_VBR | BTR_MPEG_BIT_RATE_320000 | BTR_MPEG_BIT_RATE_256000 |
1027  BTR_MPEG_BIT_RATE_224000 | BTR_MPEG_BIT_RATE_192000 | BTR_MPEG_BIT_RATE_160000 |
1028  BTR_MPEG_BIT_RATE_128000 | BTR_MPEG_BIT_RATE_112000 | BTR_MPEG_BIT_RATE_96000 |
1029  BTR_MPEG_BIT_RATE_80000 | BTR_MPEG_BIT_RATE_64000 | BTR_MPEG_BIT_RATE_56000 |
1030  BTR_MPEG_BIT_RATE_48000 | BTR_MPEG_BIT_RATE_40000 | BTR_MPEG_BIT_RATE_32000));
1031 
1032 #if 0
1033  lBtAVMediaASinkRegRet = BtrCore_BTRegisterMedia(apBtConn,
1034  apBtAdapter,
1035  enBTDevAudioSink,
1036  enBTMediaTypeAAC,
1038  (void*)&lstBtA2dpAacCaps,
1039  sizeof(lstBtA2dpAacCaps),
1040  lBtAVMediaDelayReport);
1041 #endif
1042 
1043  lBtAVMediaASrcRegRet = BtrCore_BTRegisterMedia(apBtConn,
1044  apBtAdapter,
1045  enBTDevAudioSource,
1046  enBTMediaTypeAAC,
1048  (void*)&lstBtA2dpAacCaps,
1049  sizeof(lstBtA2dpAacCaps),
1050  lBtAVMediaDelayReport);
1051 #endif
1052 
1053  if (!lBtAVMediaASinkRegRet && !lBtAVMediaASrcRegRet)
1054  lBtAVMediaNegotiateRet = BtrCore_BTRegisterNegotiateMediaCb(apBtConn,
1055  apBtAdapter,
1056  &btrCore_AVMedia_NegotiateMediaCb,
1057  pstlhBTRCoreAVM);
1058 
1059  if (!lBtAVMediaASinkRegRet && !lBtAVMediaASrcRegRet && !lBtAVMediaNegotiateRet)
1060  lBtAVMediaTransportPRet = BtrCore_BTRegisterTransportPathMediaCb(apBtConn,
1061  apBtAdapter,
1062  &btrCore_AVMedia_TransportPathCb,
1063  pstlhBTRCoreAVM);
1064 
1065  if (!lBtAVMediaASinkRegRet && !lBtAVMediaASrcRegRet && !lBtAVMediaNegotiateRet && !lBtAVMediaTransportPRet)
1066  lBTAVMediaPlayerPRet = BtrCore_BTRegisterMediaPlayerPathCb(apBtConn,
1067  apBtAdapter,
1068  &btrCore_AVMedia_MediaPlayerPathCb,
1069  pstlhBTRCoreAVM);
1070 
1071  if (!lBtAVMediaASinkRegRet && !lBtAVMediaASrcRegRet && !lBtAVMediaNegotiateRet && !lBtAVMediaTransportPRet && !lBTAVMediaPlayerPRet)
1072  lBTAVMediaStatusRet = BtrCore_BTRegisterMediaStatusUpdateCb(apBtConn,
1073  &btrCore_AVMedia_MediaStatusUpdateCb,
1074  pstlhBTRCoreAVM);
1075 
1076  if (!lBtAVMediaASinkRegRet && !lBtAVMediaASrcRegRet && !lBtAVMediaNegotiateRet && !lBtAVMediaTransportPRet && !lBTAVMediaPlayerPRet && !lBTAVMediaStatusRet)
1077  lBTAVMediaBrowserRet = BtrCore_BTRegisterMediaBrowserUpdateCb(apBtConn,
1078  &btrCore_AVMedia_MediaBrowserUpdateCb,
1079  pstlhBTRCoreAVM);
1080 
1081  if (!lBtAVMediaASinkRegRet && !lBtAVMediaASrcRegRet && !lBtAVMediaNegotiateRet && !lBtAVMediaTransportPRet &&
1082  !lBTAVMediaPlayerPRet && !lBTAVMediaStatusRet && !lBTAVMediaBrowserRet)
1083  lenBTRCoreRet = enBTRCoreSuccess;
1084 
1085  if (lenBTRCoreRet != enBTRCoreSuccess) {
1086  free(pstlhBTRCoreAVM);
1087  pstlhBTRCoreAVM = NULL;
1088  }
1089 
1090  *phBTRCoreAVM = (tBTRCoreAVMediaHdl)pstlhBTRCoreAVM;
1091 
1092  return lenBTRCoreRet;
1093 }
1094 
1095 
1096 enBTRCoreRet
1098  tBTRCoreAVMediaHdl hBTRCoreAVM,
1099  void* apBtConn,
1100  const char* apBtAdapter
1101 ) {
1102  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
1103  int lBtAVMediaASinkUnRegRet = -1;
1104  int lBtAVMediaASrcUnRegRet = -1;
1105  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
1106 
1107  if (!hBTRCoreAVM || !apBtConn || !apBtAdapter) {
1108  return enBTRCoreInvalidArg;
1109  }
1110 
1111  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
1112 
1113  if (pstlhBTRCoreAVM->btIfceHdl != apBtConn) {
1114  BTRCORELOG_WARN ("Incorrect Argument - btIfceHdl : Continue\n");
1115  }
1116 
1117 
1118 #if defined(AAC_SUPPORTED)
1119  lBtAVMediaASrcUnRegRet = BtrCore_BTUnRegisterMedia(apBtConn,
1120  apBtAdapter,
1121  enBTDevAudioSource,
1122  enBTMediaTypeAAC);
1123 
1124 #if 0
1125  lBtAVMediaASinkUnRegRet = BtrCore_BTUnRegisterMedia(apBtConn,
1126  apBtAdapter,
1127  enBTDevAudioSink,
1128  enBTMediaTypeAAC);
1129 #endif
1130 #endif
1131 
1132  lBtAVMediaASrcUnRegRet = BtrCore_BTUnRegisterMedia(apBtConn,
1133  apBtAdapter,
1134  enBTDevAudioSource,
1135  enBTMediaTypeSBC);
1136 
1137  lBtAVMediaASinkUnRegRet = BtrCore_BTUnRegisterMedia(apBtConn,
1138  apBtAdapter,
1139  enBTDevAudioSink,
1140  enBTMediaTypeSBC);
1141 
1142  if (pstlhBTRCoreAVM->pstBTMediaConfigIn) {
1143  free(pstlhBTRCoreAVM->pstBTMediaConfigIn);
1144  pstlhBTRCoreAVM->pstBTMediaConfigIn = NULL;
1145  }
1146 
1147  if (pstlhBTRCoreAVM->pstBTMediaConfigOut) {
1148  free(pstlhBTRCoreAVM->pstBTMediaConfigOut);
1149  pstlhBTRCoreAVM->pstBTMediaConfigOut = NULL;
1150  }
1151 
1152  if (pstlhBTRCoreAVM->pcAVMediaTransportPathOut) {
1153  free(pstlhBTRCoreAVM->pcAVMediaTransportPathOut);
1154  pstlhBTRCoreAVM->pcAVMediaTransportPathOut = NULL;
1155  }
1156 
1157  if (pstlhBTRCoreAVM->pcAVMediaControlPath) {
1158  free(pstlhBTRCoreAVM->pcAVMediaControlPath);
1159  pstlhBTRCoreAVM->pcAVMediaControlPath = NULL;
1160  }
1161 
1162  if (pstlhBTRCoreAVM->pcAVMediaTransportPathIn) {
1163  free(pstlhBTRCoreAVM->pcAVMediaTransportPathIn);
1164  pstlhBTRCoreAVM->pcAVMediaTransportPathIn = NULL;
1165  }
1166 
1167  if (pstlhBTRCoreAVM->pcAVMediaPlayerPath) {
1168  free(pstlhBTRCoreAVM->pcAVMediaPlayerPath);
1169  pstlhBTRCoreAVM->pcAVMediaPlayerPath = NULL;
1170  }
1171 
1172  if (pstlhBTRCoreAVM->pstAVMediaBrowser) {
1173  const char* apcBtDevAddr = NULL; /* TODO get device Address */
1174  while (pstlhBTRCoreAVM->pstAVMediaBrowser->pvAVMediaParentItem) {
1175  pstlhBTRCoreAVM->pstAVMediaBrowser = pstlhBTRCoreAVM->pstAVMediaBrowser->pvAVMediaParentItem;
1176  }
1177  if (!btrCore_AVMedia_DeallocateUnhandledBrowserMemory (pstlhBTRCoreAVM, apcBtDevAddr, &pstlhBTRCoreAVM->pstAVMediaBrowser)) {
1178  BTRCORELOG_ERROR ("Media Browser Error - Deallocate Unhandled Browser Memory Failed!\n");
1179  }
1180  pstlhBTRCoreAVM->pstAVMediaBrowser = NULL;
1181  }
1182 
1183  if (pstlhBTRCoreAVM->pstAVMediaPlayList) {
1184  const char* apcBtDevAddr = NULL; /* TODO get device Address */
1185  if (!btrCore_AVMedia_DeallocateUnhandledBrowserMemory (pstlhBTRCoreAVM, apcBtDevAddr, &pstlhBTRCoreAVM->pstAVMediaPlayList)) {
1186  BTRCORELOG_ERROR ("Media Browser Error - Deallocate Unhandled Browser Memory Failed!\n");
1187  }
1188  pstlhBTRCoreAVM->pstAVMediaPlayList = NULL;
1189  }
1190 
1191  pstlhBTRCoreAVM->ui8AVMediaTransportVolume = 0;
1192  pstlhBTRCoreAVM->bAVMediaTrVolAvrcp = FALSE;
1193  pstlhBTRCoreAVM->btIfceHdl = NULL;
1194  pstlhBTRCoreAVM->pvThreadData = NULL;
1195  pstlhBTRCoreAVM->pcBMediaStatusUserData = NULL;
1196  pstlhBTRCoreAVM->fpcBBTRCoreAVMediaStatusUpdate = NULL;
1197  pstlhBTRCoreAVM->eAVMTState = enAVMTransportStDisconnected;
1198 
1199  if (!lBtAVMediaASrcUnRegRet && !lBtAVMediaASinkUnRegRet)
1200  lenBTRCoreRet = enBTRCoreSuccess;
1201 
1202 
1203  if (hBTRCoreAVM) {
1204  (void) pstlhBTRCoreAVM;
1205  free(hBTRCoreAVM);
1206  hBTRCoreAVM = NULL;
1207  }
1208 
1209  return lenBTRCoreRet;
1210 }
1211 
1212 
1213 enBTRCoreRet
1215  tBTRCoreAVMediaHdl hBTRCoreAVM,
1216  const char* apBtDevAddr,
1217  stBTRCoreAVMediaInfo* apstBtrCoreAVMediaInfo
1218 ) {
1219  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
1220  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
1221  void* lpstBTMediaConfig = NULL;
1222 
1223  if (!hBTRCoreAVM || !apBtDevAddr || !apstBtrCoreAVMediaInfo) {
1224  return enBTRCoreInvalidArg;
1225  }
1226 
1227  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
1228 
1229 
1230  if (apstBtrCoreAVMediaInfo->eBtrCoreAVMFlow == eBTRCoreAVMediaFlowOut) {
1231  /* Max 4 sec timeout - Polled at 200ms second interval */
1232  unsigned int ui32sleepIdx = 20;
1233  do {
1234  sched_yield();
1235  usleep(200000);
1236  } while ((!pstlhBTRCoreAVM->pcAVMediaTransportPathOut) && (--ui32sleepIdx));
1237 
1238  lpstBTMediaConfig = pstlhBTRCoreAVM->pstBTMediaConfigOut;
1239  apstBtrCoreAVMediaInfo->eBtrCoreAVMType = pstlhBTRCoreAVM->eAVMediaTypeOut;
1240  }
1241  else if (apstBtrCoreAVMediaInfo->eBtrCoreAVMFlow == eBTRCoreAVMediaFlowIn) {
1242  /* Max 4 sec timeout - Polled at 200ms second interval */
1243  unsigned int ui32sleepIdx = 20;
1244  do {
1245  sched_yield();
1246  usleep(200000);
1247  } while ((!pstlhBTRCoreAVM->pcAVMediaTransportPathIn) && (--ui32sleepIdx));
1248 
1249  lpstBTMediaConfig = pstlhBTRCoreAVM->pstBTMediaConfigIn;
1250  apstBtrCoreAVMediaInfo->eBtrCoreAVMType = pstlhBTRCoreAVM->eAVMediaTypeIn;
1251  }
1252  else {
1253  //TODO: Handle Other flows and default
1254  lpstBTMediaConfig = pstlhBTRCoreAVM->pstBTMediaConfigOut;
1255  apstBtrCoreAVMediaInfo->eBtrCoreAVMType = pstlhBTRCoreAVM->eAVMediaTypeOut;
1256  }
1257 
1258 
1259  if (!apstBtrCoreAVMediaInfo->pstBtrCoreAVMCodecInfo || !lpstBTMediaConfig) {
1260  return enBTRCoreFailure;
1261  }
1262 
1263 
1264  if (apstBtrCoreAVMediaInfo->eBtrCoreAVMType == eBTRCoreAVMTypePCM) {
1265  }
1266  else if (apstBtrCoreAVMediaInfo->eBtrCoreAVMType == eBTRCoreAVMTypeSBC) {
1267  a2dp_sbc_t* lpstBTMediaSbcConfig = (a2dp_sbc_t*)lpstBTMediaConfig;
1268  stBTRCoreAVMediaSbcInfo* pstBtrCoreAVMediaSbcInfo = (stBTRCoreAVMediaSbcInfo*)(apstBtrCoreAVMediaInfo->pstBtrCoreAVMCodecInfo);
1269 
1270  if (lpstBTMediaSbcConfig->frequency == BTR_SBC_SAMPLING_FREQ_16000) {
1271  pstBtrCoreAVMediaSbcInfo->ui32AVMSFreq = 16000;
1272  }
1273  else if (lpstBTMediaSbcConfig->frequency == BTR_SBC_SAMPLING_FREQ_32000) {
1274  pstBtrCoreAVMediaSbcInfo->ui32AVMSFreq = 32000;
1275  }
1276  else if (lpstBTMediaSbcConfig->frequency == BTR_SBC_SAMPLING_FREQ_44100) {
1277  pstBtrCoreAVMediaSbcInfo->ui32AVMSFreq = 44100;
1278  }
1279  else if (lpstBTMediaSbcConfig->frequency == BTR_SBC_SAMPLING_FREQ_48000) {
1280  pstBtrCoreAVMediaSbcInfo->ui32AVMSFreq = 48000;
1281  }
1282  else {
1283  pstBtrCoreAVMediaSbcInfo->ui32AVMSFreq = 0;
1284  }
1285 
1286  if (lpstBTMediaSbcConfig->channel_mode == BTR_SBC_CHANNEL_MODE_MONO) {
1287  pstBtrCoreAVMediaSbcInfo->eAVMAChan = eBTRCoreAVMAChanMono;
1288  pstBtrCoreAVMediaSbcInfo->ui32AVMAChan = 1;
1289  }
1290  else if (lpstBTMediaSbcConfig->channel_mode == BTR_SBC_CHANNEL_MODE_DUAL_CHANNEL) {
1291  pstBtrCoreAVMediaSbcInfo->eAVMAChan = eBTRCoreAVMAChanDualChannel;
1292  pstBtrCoreAVMediaSbcInfo->ui32AVMAChan = 2;
1293  }
1294  else if (lpstBTMediaSbcConfig->channel_mode == BTR_SBC_CHANNEL_MODE_STEREO) {
1295  pstBtrCoreAVMediaSbcInfo->eAVMAChan = eBTRCoreAVMAChanStereo;
1296  pstBtrCoreAVMediaSbcInfo->ui32AVMAChan = 2;
1297  }
1298  else if (lpstBTMediaSbcConfig->channel_mode == BTR_SBC_CHANNEL_MODE_JOINT_STEREO) {
1299  pstBtrCoreAVMediaSbcInfo->eAVMAChan = eBTRCoreAVMAChanJointStereo;
1300  pstBtrCoreAVMediaSbcInfo->ui32AVMAChan = 2;
1301  }
1302  else {
1303  pstBtrCoreAVMediaSbcInfo->eAVMAChan = eBTRCoreAVMAChanUnknown;
1304  }
1305 
1306  pstBtrCoreAVMediaSbcInfo->ui8AVMSbcAllocMethod = lpstBTMediaSbcConfig->allocation_method;
1307 
1308  if (lpstBTMediaSbcConfig->subbands == BTR_SBC_SUBBANDS_4) {
1309  pstBtrCoreAVMediaSbcInfo->ui8AVMSbcSubbands = 4;
1310  }
1311  else if (lpstBTMediaSbcConfig->subbands == BTR_SBC_SUBBANDS_8) {
1312  pstBtrCoreAVMediaSbcInfo->ui8AVMSbcSubbands = 8;
1313  }
1314  else {
1315  pstBtrCoreAVMediaSbcInfo->ui8AVMSbcSubbands = 0;
1316  }
1317 
1318  if (lpstBTMediaSbcConfig->block_length == BTR_SBC_BLOCK_LENGTH_4) {
1319  pstBtrCoreAVMediaSbcInfo->ui8AVMSbcBlockLength = 4;
1320  }
1321  else if (lpstBTMediaSbcConfig->block_length == BTR_SBC_BLOCK_LENGTH_8) {
1322  pstBtrCoreAVMediaSbcInfo->ui8AVMSbcBlockLength = 8;
1323  }
1324  else if (lpstBTMediaSbcConfig->block_length == BTR_SBC_BLOCK_LENGTH_12) {
1325  pstBtrCoreAVMediaSbcInfo->ui8AVMSbcBlockLength = 12;
1326  }
1327  else if (lpstBTMediaSbcConfig->block_length == BTR_SBC_BLOCK_LENGTH_16) {
1328  pstBtrCoreAVMediaSbcInfo->ui8AVMSbcBlockLength = 16;
1329  }
1330  else {
1331  pstBtrCoreAVMediaSbcInfo->ui8AVMSbcBlockLength = 0;
1332  }
1333 
1334  pstBtrCoreAVMediaSbcInfo->ui8AVMSbcMinBitpool = lpstBTMediaSbcConfig->min_bitpool;
1335  pstBtrCoreAVMediaSbcInfo->ui8AVMSbcMaxBitpool = lpstBTMediaSbcConfig->max_bitpool;
1336 
1337  if ((lpstBTMediaSbcConfig->channel_mode == BTR_SBC_CHANNEL_MODE_MONO) ||
1338  (lpstBTMediaSbcConfig->channel_mode == BTR_SBC_CHANNEL_MODE_DUAL_CHANNEL)) {
1339  pstBtrCoreAVMediaSbcInfo->ui16AVMSbcFrameLen = 4 + ((4 * pstBtrCoreAVMediaSbcInfo->ui8AVMSbcSubbands * pstBtrCoreAVMediaSbcInfo->ui32AVMAChan) / 8) +
1340  ((pstBtrCoreAVMediaSbcInfo->ui8AVMSbcBlockLength * pstBtrCoreAVMediaSbcInfo->ui32AVMAChan * pstBtrCoreAVMediaSbcInfo->ui8AVMSbcMaxBitpool) / 8);
1341  }
1342  else if (lpstBTMediaSbcConfig->channel_mode == BTR_SBC_CHANNEL_MODE_STEREO) {
1343  pstBtrCoreAVMediaSbcInfo->ui16AVMSbcFrameLen = 4 + (4 * pstBtrCoreAVMediaSbcInfo->ui8AVMSbcSubbands * pstBtrCoreAVMediaSbcInfo->ui32AVMAChan) / 8 +
1344  (pstBtrCoreAVMediaSbcInfo->ui8AVMSbcBlockLength * pstBtrCoreAVMediaSbcInfo->ui8AVMSbcMaxBitpool) / 8;
1345  }
1346  else if (lpstBTMediaSbcConfig->channel_mode == BTR_SBC_CHANNEL_MODE_JOINT_STEREO) {
1347  pstBtrCoreAVMediaSbcInfo->ui16AVMSbcFrameLen = 4 + ((4 * pstBtrCoreAVMediaSbcInfo->ui8AVMSbcSubbands * pstBtrCoreAVMediaSbcInfo->ui32AVMAChan) / 8) +
1348  (pstBtrCoreAVMediaSbcInfo->ui8AVMSbcSubbands + (pstBtrCoreAVMediaSbcInfo->ui8AVMSbcBlockLength * pstBtrCoreAVMediaSbcInfo->ui8AVMSbcMaxBitpool)) / 8;
1349  }
1350  else {
1351  pstBtrCoreAVMediaSbcInfo->ui16AVMSbcFrameLen = 0;
1352  }
1353 
1354  if ((pstBtrCoreAVMediaSbcInfo->ui8AVMSbcBlockLength != 0) && (pstBtrCoreAVMediaSbcInfo->ui8AVMSbcSubbands != 0))
1355  pstBtrCoreAVMediaSbcInfo->ui16AVMSbcBitrate = ((8.0 * pstBtrCoreAVMediaSbcInfo->ui16AVMSbcFrameLen * (float)pstBtrCoreAVMediaSbcInfo->ui32AVMSFreq/1000) / pstBtrCoreAVMediaSbcInfo->ui8AVMSbcSubbands) / pstBtrCoreAVMediaSbcInfo->ui8AVMSbcBlockLength;
1356  else
1357  pstBtrCoreAVMediaSbcInfo->ui16AVMSbcBitrate = 0;
1358 
1359  BTRCORELOG_TRACE ("ui32AVMSFreq = %d\n", pstBtrCoreAVMediaSbcInfo->ui32AVMSFreq);
1360  BTRCORELOG_TRACE ("ui32AVMAChan = %d\n", pstBtrCoreAVMediaSbcInfo->ui32AVMAChan);
1361  BTRCORELOG_TRACE ("ui8AVMSbcAllocMethod = %d\n", pstBtrCoreAVMediaSbcInfo->ui8AVMSbcAllocMethod);
1362  BTRCORELOG_TRACE ("ui8AVMSbcSubbands = %d\n", pstBtrCoreAVMediaSbcInfo->ui8AVMSbcSubbands);
1363  BTRCORELOG_TRACE ("ui8AVMSbcBlockLength = %d\n", pstBtrCoreAVMediaSbcInfo->ui8AVMSbcBlockLength);
1364  BTRCORELOG_TRACE ("ui8AVMSbcMinBitpool = %d\n", pstBtrCoreAVMediaSbcInfo->ui8AVMSbcMinBitpool);
1365  BTRCORELOG_TRACE ("ui8AVMSbcMaxBitpool = %d\n", pstBtrCoreAVMediaSbcInfo->ui8AVMSbcMaxBitpool);
1366  BTRCORELOG_TRACE ("ui16AVMSbcFrameLen = %d\n", pstBtrCoreAVMediaSbcInfo->ui16AVMSbcFrameLen);
1367  BTRCORELOG_DEBUG ("ui16AVMSbcBitrate = %d\n", pstBtrCoreAVMediaSbcInfo->ui16AVMSbcBitrate);
1368 
1369  if (pstBtrCoreAVMediaSbcInfo->ui32AVMSFreq && pstBtrCoreAVMediaSbcInfo->ui16AVMSbcBitrate)
1370  lenBTRCoreRet = enBTRCoreSuccess;
1371 
1372  }
1373  else if (apstBtrCoreAVMediaInfo->eBtrCoreAVMType == eBTRCoreAVMTypeMPEG) {
1374  }
1375  else if (apstBtrCoreAVMediaInfo->eBtrCoreAVMType == eBTRCoreAVMTypeAAC) {
1376 #if defined(AAC_SUPPORTED)
1377  unsigned short ui16AacFreq = 0;
1378  unsigned short ui16AacBitrate= 0;
1379  a2dp_aac_t* lpstBTMediaAacConfig = (a2dp_aac_t*)lpstBTMediaConfig;
1380  stBTRCoreAVMediaMpegInfo* pstBtrCoreAVMediaAacInfo = (stBTRCoreAVMediaMpegInfo*)(apstBtrCoreAVMediaInfo->pstBtrCoreAVMCodecInfo);
1381 
1382  ui16AacFreq = BTR_AAC_GET_FREQ(*lpstBTMediaAacConfig);
1383  if (ui16AacFreq & BTR_AAC_SAMPLING_FREQ_8000) {
1384  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 8000;
1385  }
1386  else if (ui16AacFreq & BTR_AAC_SAMPLING_FREQ_11025) {
1387  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 11025;
1388  }
1389  else if (ui16AacFreq & BTR_AAC_SAMPLING_FREQ_12000) {
1390  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 12000;
1391  }
1392  else if (ui16AacFreq & BTR_AAC_SAMPLING_FREQ_16000) {
1393  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 16000;
1394  }
1395  else if (ui16AacFreq & BTR_AAC_SAMPLING_FREQ_22050) {
1396  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 22050;
1397  }
1398  else if (ui16AacFreq & BTR_AAC_SAMPLING_FREQ_24000) {
1399  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 24000;
1400  }
1401  else if (ui16AacFreq & BTR_AAC_SAMPLING_FREQ_32000) {
1402  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 32000;
1403  }
1404  else if (ui16AacFreq & BTR_AAC_SAMPLING_FREQ_44100) {
1405  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 44100;
1406  }
1407  else if (ui16AacFreq & BTR_AAC_SAMPLING_FREQ_48000) {
1408  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 48000;
1409  }
1410  else if (ui16AacFreq & BTR_AAC_SAMPLING_FREQ_64000) {
1411  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 64000;
1412  }
1413  else if (ui16AacFreq & BTR_AAC_SAMPLING_FREQ_88200) {
1414  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 88200;
1415  }
1416  else if (ui16AacFreq & BTR_AAC_SAMPLING_FREQ_96000) {
1417  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 96000;
1418  }
1419  else {
1420  pstBtrCoreAVMediaAacInfo->ui32AVMSFreq = 0;
1421  }
1422 
1423  ui16AacBitrate = BTR_AAC_GET_BITRATE(*lpstBTMediaAacConfig);
1424  if (ui16AacBitrate & BTR_MPEG_BIT_RATE_VBR) {
1425  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 1;
1426  }
1427  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_320000) {
1428  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 320;
1429  }
1430  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_256000) {
1431  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 256;
1432  }
1433  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_224000) {
1434  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 224;
1435  }
1436  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_192000) {
1437  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 192;
1438  }
1439  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_160000) {
1440  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 160;
1441  }
1442  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_128000) {
1443  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 128;
1444  }
1445  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_112000) {
1446  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 112;
1447  }
1448  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_96000) {
1449  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 96;
1450  }
1451  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_80000) {
1452  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 80;
1453  }
1454  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_64000) {
1455  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 64;
1456  }
1457  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_56000) {
1458  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 56;
1459  }
1460  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_48000) {
1461  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 48;
1462  }
1463  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_40000) {
1464  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 40;
1465  }
1466  else if (ui16AacBitrate & BTR_MPEG_BIT_RATE_32000) {
1467  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 32;
1468  }
1469  else {
1470  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = 0;
1471  }
1472 
1473 
1474  if (lpstBTMediaAacConfig->vbr) {
1475  pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate = lpstBTMediaAacConfig->vbr;
1476  }
1477 
1478  pstBtrCoreAVMediaAacInfo->ui8AVMMpegRfa = lpstBTMediaAacConfig->rfa;
1479 
1480  if (lpstBTMediaAacConfig->channels & BTR_AAC_CHANNELS_1) {
1481  pstBtrCoreAVMediaAacInfo->eAVMAChan = eBTRCoreAVMAChanMono;
1482  pstBtrCoreAVMediaAacInfo->ui32AVMAChan = 1;
1483  }
1484  else if (lpstBTMediaAacConfig->channels & BTR_AAC_CHANNELS_2) {
1485  pstBtrCoreAVMediaAacInfo->eAVMAChan = eBTRCoreAVMAChanStereo;
1486  pstBtrCoreAVMediaAacInfo->ui32AVMAChan = 2;
1487  }
1488  else {
1489  pstBtrCoreAVMediaAacInfo->eAVMAChan = eBTRCoreAVMAChanUnknown;
1490  pstBtrCoreAVMediaAacInfo->ui32AVMAChan = 0;
1491  }
1492 
1493  if (lpstBTMediaAacConfig->object_type == BTR_AAC_OT_MPEG2_AAC_LC) {
1494  pstBtrCoreAVMediaAacInfo->ui8AVMMpegVersion = 2;
1495  pstBtrCoreAVMediaAacInfo->ui8AVMMpegType = 4;
1496  }
1497  else if (lpstBTMediaAacConfig->object_type == BTR_AAC_OT_MPEG4_AAC_LC) {
1498  pstBtrCoreAVMediaAacInfo->ui8AVMMpegVersion = 4;
1499  pstBtrCoreAVMediaAacInfo->ui8AVMMpegType = 4;
1500  }
1501  else if (lpstBTMediaAacConfig->object_type == BTR_AAC_OT_MPEG4_AAC_LTP) {
1502  pstBtrCoreAVMediaAacInfo->ui8AVMMpegVersion = 4;
1503  pstBtrCoreAVMediaAacInfo->ui8AVMMpegType = 4;
1504  }
1505  else if (lpstBTMediaAacConfig->object_type == BTR_AAC_OT_MPEG4_AAC_SCA) {
1506  pstBtrCoreAVMediaAacInfo->ui8AVMMpegVersion = 4;
1507  pstBtrCoreAVMediaAacInfo->ui8AVMMpegType = 4;
1508  }
1509  else {
1510  pstBtrCoreAVMediaAacInfo->ui8AVMMpegVersion = 0;
1511  pstBtrCoreAVMediaAacInfo->ui8AVMMpegType = 0;
1512  }
1513 
1514 
1515  BTRCORELOG_TRACE ("eAVMAChan = %d\n", pstBtrCoreAVMediaAacInfo->eAVMAChan);
1516  BTRCORELOG_TRACE ("ui32AVMAChan = %d\n", pstBtrCoreAVMediaAacInfo->ui32AVMAChan);
1517  BTRCORELOG_DEBUG ("ui32AVMSFreq = %d\n", pstBtrCoreAVMediaAacInfo->ui32AVMSFreq);
1518  BTRCORELOG_TRACE ("ui8AVMMpegVersion = %d\n", pstBtrCoreAVMediaAacInfo->ui8AVMMpegVersion);
1519  BTRCORELOG_TRACE ("ui8AVMMpegLayer = %d\n", pstBtrCoreAVMediaAacInfo->ui8AVMMpegLayer);
1520  BTRCORELOG_TRACE ("ui8AVMMpegType = %d\n", pstBtrCoreAVMediaAacInfo->ui8AVMMpegType);
1521  BTRCORELOG_TRACE ("ui8AVMMpegMpf = %d\n", pstBtrCoreAVMediaAacInfo->ui8AVMMpegMpf);
1522  BTRCORELOG_TRACE ("ui8AVMMpegRfa = %d\n", pstBtrCoreAVMediaAacInfo->ui8AVMMpegRfa);
1523  BTRCORELOG_TRACE ("ui16AVMMpegFrameLen = %d\n", pstBtrCoreAVMediaAacInfo->ui16AVMMpegFrameLen);
1524  BTRCORELOG_DEBUG ("ui16AVMMpegBitrate = %d\n", pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate);
1525 
1526  if (pstBtrCoreAVMediaAacInfo->ui32AVMSFreq && pstBtrCoreAVMediaAacInfo->ui16AVMMpegBitrate)
1527  lenBTRCoreRet = enBTRCoreSuccess;
1528 
1529 #endif
1530  }
1531 
1532 
1533  return lenBTRCoreRet;
1534 }
1535 
1536 
1537 enBTRCoreRet
1539  tBTRCoreAVMediaHdl hBTRCoreAVM,
1540  const char* apBtDevAddr,
1541  int* apDataPath,
1542  int* apDataReadMTU,
1543  int* apDataWriteMTU,
1544  unsigned int* apui32Delay
1545 ) {
1546  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
1547  char* lpcAVMediaTransportPath = NULL;
1548  int lBtAVMediaRet = -1;
1549  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
1550  unBTOpIfceProp lunBtOpMedTProp;
1551  unsigned int ui32Delay = 0xFFFFu;
1552  unsigned short ui16Vol = 0xFFFFu;
1553 
1554  if (!hBTRCoreAVM || !apBtDevAddr || !apui32Delay) {
1555  return enBTRCoreInvalidArg;
1556  }
1557 
1558  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
1559 
1560 
1561  if (pstlhBTRCoreAVM->pcAVMediaTransportPathOut && strstr(pstlhBTRCoreAVM->pcAVMediaTransportPathOut, apBtDevAddr)) {
1562  lpcAVMediaTransportPath = pstlhBTRCoreAVM->pcAVMediaTransportPathOut;
1563  }
1564  else if (pstlhBTRCoreAVM->pcAVMediaTransportPathIn && strstr(pstlhBTRCoreAVM->pcAVMediaTransportPathIn, apBtDevAddr)) {
1565  lpcAVMediaTransportPath = pstlhBTRCoreAVM->pcAVMediaTransportPathIn;
1566  }
1567 
1568 
1569  if (lpcAVMediaTransportPath == NULL) {
1570  return enBTRCoreFailure;
1571  }
1572 
1573  if (!(lBtAVMediaRet = BtrCore_BTAcquireDevDataPath(pstlhBTRCoreAVM->btIfceHdl, lpcAVMediaTransportPath, apDataPath, apDataReadMTU, apDataWriteMTU)))
1574  lenBTRCoreRet = enBTRCoreSuccess;
1575 
1576  lunBtOpMedTProp.enBtMediaTransportProp = enBTMedTPropDelay;
1577  if ((lBtAVMediaRet = BtrCore_BTGetProp(pstlhBTRCoreAVM->btIfceHdl, lpcAVMediaTransportPath, enBTMediaTransport, lunBtOpMedTProp, &ui32Delay)))
1578  lenBTRCoreRet = enBTRCoreFailure;
1579 
1580  lunBtOpMedTProp.enBtMediaTransportProp = enBTMedTPropVol;
1581  if ((lBtAVMediaRet = BtrCore_BTGetProp(pstlhBTRCoreAVM->btIfceHdl, lpcAVMediaTransportPath, enBTMediaTransport, lunBtOpMedTProp, &ui16Vol)))
1582  lenBTRCoreRet = enBTRCoreFailure;
1583 
1584  *apui32Delay = ui32Delay;
1585  BTRCORELOG_INFO ("BTRCore_AVMedia_AcquireDataPath: Delay value = %d Volume = %d\n", ui32Delay, ui16Vol);
1586 
1587  return lenBTRCoreRet;
1588 }
1589 
1590 
1591 enBTRCoreRet
1593  tBTRCoreAVMediaHdl hBTRCoreAVM,
1594  const char* apBtDevAddr
1595 ) {
1596  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
1597  char* lpcAVMediaTransportPath = NULL;
1598  int lBtAVMediaRet = -1;
1599  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
1600 
1601  if (!hBTRCoreAVM || !apBtDevAddr) {
1602  return enBTRCoreInvalidArg;
1603  }
1604 
1605  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
1606 
1607 
1608  if (pstlhBTRCoreAVM->pcAVMediaTransportPathOut && strstr(pstlhBTRCoreAVM->pcAVMediaTransportPathOut, apBtDevAddr)) {
1609  lpcAVMediaTransportPath = pstlhBTRCoreAVM->pcAVMediaTransportPathOut;
1610  }
1611  else if (pstlhBTRCoreAVM->pcAVMediaTransportPathIn && strstr(pstlhBTRCoreAVM->pcAVMediaTransportPathIn, apBtDevAddr)) {
1612  lpcAVMediaTransportPath = pstlhBTRCoreAVM->pcAVMediaTransportPathIn;
1613  }
1614 
1615 
1616  if (lpcAVMediaTransportPath == NULL) {
1617  return enBTRCoreFailure;
1618  }
1619 
1620 
1621  if (!(lBtAVMediaRet = BtrCore_BTReleaseDevDataPath(pstlhBTRCoreAVM->btIfceHdl, lpcAVMediaTransportPath)))
1622  lenBTRCoreRet = enBTRCoreSuccess;
1623 
1624  return lenBTRCoreRet;
1625 }
1626 
1627 
1628 enBTRCoreRet
1630  tBTRCoreAVMediaHdl hBTRCoreAVM,
1631  const char* apBtDevAddr,
1632  enBTRCoreAVMediaCtrl aenBTRCoreAVMediaCtrl,
1633  eBTRCoreAVMediaFlow aenBTRCoreAVMediaFlow,
1634  stBTRCoreAVMediaCtData* apstBTRCoreAVMediaCtrlData
1635 ) {
1636  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
1637  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
1638  enBTMediaControlCmd aenBTMediaControl = 0;
1639  unBTOpIfceProp lunBtOpMedTProp;
1640  unsigned short lui16TranspVol = 0xFFFFu;
1641 
1642 
1643  if (!hBTRCoreAVM) {
1644  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
1645  return enBTRCoreInvalidArg;
1646  }
1647 
1648  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
1649 
1650  if ((aenBTRCoreAVMediaFlow == eBTRCoreAVMediaFlowIn) &&
1651  (!pstlhBTRCoreAVM->pcAVMediaPlayerPath)) {
1652  //TODO: The pcAVMediaPlayerPath changes during transition between Players on Smartphone (Local->Youtube->Local)
1653  // Seems to be the root cause of the stack corruption as part of DELIA-25861
1654  char* lpcAVMediaPlayerPath = BtrCore_BTGetMediaPlayerPath(pstlhBTRCoreAVM->btIfceHdl, apBtDevAddr);
1655  if (!lpcAVMediaPlayerPath || !(pstlhBTRCoreAVM->pcAVMediaPlayerPath = strndup(lpcAVMediaPlayerPath, BTRCORE_MAX_STR_LEN - 1))) {
1656  BTRCORELOG_ERROR ("Failed to get Media Player Object!!!");
1657  return enBTRCoreFailure;
1658  }
1659  }
1660 
1661  switch (aenBTRCoreAVMediaCtrl) {
1662  case enBTRCoreAVMediaCtrlPlay:
1663  aenBTMediaControl = enBTMediaCtrlPlay;
1664  break;
1665  case enBTRCoreAVMediaCtrlPause:
1666  aenBTMediaControl = enBTMediaCtrlPause;
1667  break;
1668  case enBTRCoreAVMediaCtrlStop:
1669  aenBTMediaControl = enBTMediaCtrlStop;
1670  break;
1671  case enBTRCoreAVMediaCtrlNext:
1672  aenBTMediaControl = enBTMediaCtrlNext;
1673  break;
1674  case enBTRCoreAVMediaCtrlPrevious:
1675  aenBTMediaControl = enBTMediaCtrlPrevious;
1676  break;
1677  case enBTRCoreAVMediaCtrlFastForward:
1678  aenBTMediaControl = enBTMediaCtrlFastForward;
1679  break;
1680  case enBTRCoreAVMediaCtrlRewind:
1681  aenBTMediaControl = enBTMediaCtrlRewind;
1682  break;
1683  case enBTRCoreAVMediaCtrlVolumeUp:
1684  aenBTMediaControl = enBTMediaCtrlVolumeUp;
1685  if (apstBTRCoreAVMediaCtrlData != NULL) {
1686  lui16TranspVol = (apstBTRCoreAVMediaCtrlData->m_mediaAbsTransportVolume < 255) ? (apstBTRCoreAVMediaCtrlData->m_mediaAbsTransportVolume / 2) : 127;
1687  }
1688  else {
1689  lui16TranspVol = (pstlhBTRCoreAVM->ui8AVMediaTransportVolume < 240) ? ((pstlhBTRCoreAVM->ui8AVMediaTransportVolume + 10) / 2) : 127;
1690  }
1691  break;
1692  case enBTRCoreAVMediaCtrlVolumeDown:
1693  aenBTMediaControl = enBTMediaCtrlVolumeDown;
1694  if (apstBTRCoreAVMediaCtrlData != NULL) {
1695  lui16TranspVol = (apstBTRCoreAVMediaCtrlData->m_mediaAbsTransportVolume < 255) ? (apstBTRCoreAVMediaCtrlData->m_mediaAbsTransportVolume / 2) : 127;
1696  }
1697  else {
1698  lui16TranspVol = (pstlhBTRCoreAVM->ui8AVMediaTransportVolume > 15) ? ((pstlhBTRCoreAVM->ui8AVMediaTransportVolume - 10) / 2) : 0;
1699  }
1700  break;
1701  case enBTRcoreAVMediaCtrlEqlzrOff:
1702  aenBTMediaControl = enBTMediaCtrlEqlzrOff;
1703  break;
1704  case enBTRcoreAVMediaCtrlEqlzrOn:
1705  aenBTMediaControl = enBTMediaCtrlEqlzrOn;
1706  break;
1707  case enBTRCoreAVMediaCtrlShflOff:
1708  aenBTMediaControl = enBTMediaCtrlShflOff;
1709  break;
1710  case enBTRCoreAVMediaCtrlShflAllTracks:
1711  aenBTMediaControl = enBTMediaCtrlShflAllTracks;
1712  break;
1713  case enBTRCoreAVMediaCtrlShflGroup:
1714  aenBTMediaControl = enBTMediaCtrlShflGroup;
1715  break;
1716  case enBTRCoreAVMediaCtrlRptOff:
1717  aenBTMediaControl = enBTMediaCtrlRptOff;
1718  break;
1719  case enBTRCoreAVMediaCtrlRptSingleTrack:
1720  aenBTMediaControl = enBTMediaCtrlRptSingleTrack;
1721  break;
1722  case enBTRCoreAVMediaCtrlRptAllTracks:
1723  aenBTMediaControl = enBTMediaCtrlRptAllTracks;
1724  break;
1725  case enBTRCoreAVMediaCtrlRptGroup:
1726  aenBTMediaControl = enBTMediaCtrlRptGroup;
1727  break;
1728  default:
1729  aenBTMediaControl = enBTMediaCtrlUnknown;
1730  }
1731 
1732  if (aenBTMediaControl == enBTMediaCtrlUnknown) {
1733  BTRCORELOG_ERROR ("Unknown Media Control option!\n");
1734  lenBTRCoreRet = enBTRCoreFailure;
1735  }
1736  else if (aenBTRCoreAVMediaFlow == eBTRCoreAVMediaFlowIn) {
1737  if (BtrCore_BTDevMediaControl(pstlhBTRCoreAVM->btIfceHdl, pstlhBTRCoreAVM->pcAVMediaPlayerPath, aenBTMediaControl)) {
1738  BTRCORELOG_ERROR ("Failed to set the Media control eBTRCoreAVMediaFlowIn!");
1739  lenBTRCoreRet = enBTRCoreFailure;
1740  }
1741  }
1742  else if (aenBTRCoreAVMediaFlow == eBTRCoreAVMediaFlowOut) {
1743  if (((pstlhBTRCoreAVM->bAVMediaTrVolAvrcp == TRUE) || (pstlhBTRCoreAVM->bAVMediaPlayerConnected == TRUE)) && (pstlhBTRCoreAVM->pcAVMediaTransportPathOut != NULL)) {
1744  lunBtOpMedTProp.enBtMediaTransportProp = enBTMedTPropVol;
1745  if (!BtrCore_BTSetProp(pstlhBTRCoreAVM->btIfceHdl, pstlhBTRCoreAVM->pcAVMediaTransportPathOut, enBTMediaTransport, lunBtOpMedTProp, &lui16TranspVol)) {
1746  pstlhBTRCoreAVM->ui8AVMediaTransportVolume = (lui16TranspVol == 127) ? 255 : lui16TranspVol * 2;
1747  }
1748  else {
1749  lenBTRCoreRet = enBTRCoreFailure;
1750  }
1751  }
1752  else {
1753  BTRCORELOG_ERROR ("Failed to set the Media control eBTRCoreAVMediaFlowOut!\n");
1754  lenBTRCoreRet = enBTRCoreFailure;
1755  }
1756  }
1757 
1758  return lenBTRCoreRet;
1759 }
1760 
1761 //Combine TrackInfo, PositionInfo and basic info in GetMediaProperty handling with enums and switch?
1762 enBTRCoreRet
1764  tBTRCoreAVMediaHdl hBTRCoreAVM,
1765  const char* apBtDevAddr,
1766  stBTRCoreAVMediaTrackInfo* apstBTAVMediaTrackInfo
1767 ) {
1768  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
1769  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
1770 
1771  if (!hBTRCoreAVM || !apBtDevAddr || !apstBTAVMediaTrackInfo) {
1772  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
1773  return enBTRCoreInvalidArg;
1774  }
1775 
1776  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
1777 
1778  if (!pstlhBTRCoreAVM->pcAVMediaPlayerPath) {
1779  //TODO: The pcAVMediaPlayerPath changes during transition between Players on Smartphone (Local->Youtube->Local)
1780  // Seems to be the root cause of the stack corruption as part of DELIA-25861
1781  char* lpcAVMediaPlayerPath = BtrCore_BTGetMediaPlayerPath (pstlhBTRCoreAVM->btIfceHdl, apBtDevAddr);
1782  if (!lpcAVMediaPlayerPath || !(pstlhBTRCoreAVM->pcAVMediaPlayerPath = strndup(lpcAVMediaPlayerPath, BTRCORE_MAX_STR_LEN - 1))) {
1783  BTRCORELOG_ERROR ("Failed to get Media Player Object!!!");
1784  return enBTRCoreFailure;
1785  }
1786  }
1787 
1788  if (BtrCore_BTGetTrackInformation (pstlhBTRCoreAVM->btIfceHdl, pstlhBTRCoreAVM->pcAVMediaPlayerPath, (stBTMediaTrackInfo*)apstBTAVMediaTrackInfo)) {
1789  BTRCORELOG_WARN ("Failed to get Track information!!! from Bluez !");
1790  lenBTRCoreRet = enBTRCoreFailure;
1791  }
1792 
1793  return lenBTRCoreRet;
1794 }
1795 
1796 enBTRCoreRet
1798  tBTRCoreAVMediaHdl hBTRCoreAVM,
1799  const char* apBtDevAddr,
1800  tBTRCoreAVMediaElementId aBtrAVMediaItemId,
1801  stBTRCoreAVMediaTrackInfo* apstBTAVMediaTrackInfo
1802 ) {
1803  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
1804  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
1805 
1806  if (!hBTRCoreAVM || !apBtDevAddr || !apstBTAVMediaTrackInfo) {
1807  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
1808  return enBTRCoreInvalidArg;
1809  }
1810 
1811  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
1812 
1813  if (!pstlhBTRCoreAVM->pcAVMediaPlayerPath) {
1814  //TODO: The pcAVMediaPlayerPath changes during transition between Players on Smartphone (Local->Youtube->Local)
1815  // Seems to be the root cause of the stack corruption as part of DELIA-25861
1816  char* lpcAVMediaPlayerPath = BtrCore_BTGetMediaPlayerPath (pstlhBTRCoreAVM->btIfceHdl, apBtDevAddr);
1817  if (!lpcAVMediaPlayerPath || !(pstlhBTRCoreAVM->pcAVMediaPlayerPath = strndup(lpcAVMediaPlayerPath, BTRCORE_MAX_STR_LEN - 1))) {
1818  BTRCORELOG_ERROR ("Failed to get Media Player Object!!!");
1819  return enBTRCoreFailure;
1820  }
1821  }
1822 
1823  if (aBtrAVMediaItemId && (pstlhBTRCoreAVM->SelectedaBtrAVMediaItemId == aBtrAVMediaItemId)) {
1824  if (apstBTAVMediaTrackInfo) {
1825  memset (apstBTAVMediaTrackInfo, 0 ,sizeof(stBTRCoreAVMediaTrackInfo));
1826  memcpy (apstBTAVMediaTrackInfo,&pstlhBTRCoreAVM->SelectedapstBTAVMediaTrackInfo,sizeof(stBTRCoreAVMediaTrackInfo));
1827  BTRCORELOG_DEBUG (" Get track success");
1828  return lenBTRCoreRet;
1829  }
1830  }
1831 
1832  // if aBtrAVMediaItemId is zero , get fetch the current playing elemet below
1833 
1834  if (BtrCore_BTGetTrackInformation (pstlhBTRCoreAVM->btIfceHdl, pstlhBTRCoreAVM->pcAVMediaPlayerPath, (stBTMediaTrackInfo*)apstBTAVMediaTrackInfo)) {
1835  BTRCORELOG_WARN ("Failed to get Track information!!! from Bluez !");
1836  lenBTRCoreRet = enBTRCoreFailure;
1837  }
1838 
1839  return lenBTRCoreRet;
1840 }
1841 
1842 
1843 
1844 //Combine TrackInfo, PositionInfo and basic info in GetMediaProperty handling with enums and switch?
1845 enBTRCoreRet
1847  tBTRCoreAVMediaHdl hBTRCoreAVM,
1848  const char* apBtDevAddr,
1849  stBTRCoreAVMediaPositionInfo* apstBTAVMediaPositionInfo
1850 ) {
1851  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
1852  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
1853 
1854  if (!hBTRCoreAVM || !apBtDevAddr || !apstBTAVMediaPositionInfo) {
1855  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
1856  return enBTRCoreInvalidArg;
1857  }
1858 
1859  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
1860 
1861  if (!pstlhBTRCoreAVM->pcAVMediaPlayerPath) {
1862  //TODO: The pcAVMediaPlayerPath changes during transition between Players on Smartphone (Local->Youtube->Local)
1863  // Seems to be the root cause of the stack corruption as part of DELIA-25861
1864  char* lpcAVMediaPlayerPath = BtrCore_BTGetMediaPlayerPath(pstlhBTRCoreAVM->btIfceHdl, apBtDevAddr);
1865  if (!lpcAVMediaPlayerPath || !(pstlhBTRCoreAVM->pcAVMediaPlayerPath = strndup(lpcAVMediaPlayerPath, BTRCORE_MAX_STR_LEN - 1))) {
1866  BTRCORELOG_ERROR ("Failed to get Media Player Object!!!");
1867  return enBTRCoreFailure;
1868  }
1869  }
1870 
1871  stBTRCoreAVMediaTrackInfo mediaTrackInfo;
1872  unsigned int mediaPosition = 0;
1873  enBTRCoreRet positionRet, trackRet;
1874 
1875  //TODO: The pcAVMediaPlayerPath changes during transition between Players on Smartphone (Local->Youtube->Local)
1876  // Seems to be the root cause of the stack corruption as part of DELIA-25861. This is call seems to be root cause of DELIA-25861
1877  positionRet = BtrCore_BTGetMediaPlayerProperty(pstlhBTRCoreAVM->btIfceHdl, pstlhBTRCoreAVM->pcAVMediaPlayerPath, "Position", (void*)&mediaPosition);
1878  trackRet = BtrCore_BTGetTrackInformation(pstlhBTRCoreAVM->btIfceHdl, pstlhBTRCoreAVM->pcAVMediaPlayerPath, (stBTMediaTrackInfo*)&mediaTrackInfo);
1879 
1880  if (positionRet || trackRet) {
1881  BTRCORELOG_ERROR ("Failed to get media info!!!");
1882  lenBTRCoreRet = enBTRCoreFailure;
1883  }
1884  else {
1885  apstBTAVMediaPositionInfo->ui32Duration = mediaTrackInfo.ui32Duration;
1886  apstBTAVMediaPositionInfo->ui32Position = mediaPosition;
1887  }
1888 
1889  return lenBTRCoreRet;
1890 }
1891 
1892 
1893 //Combine TrackInfo, PositionInfo and basic info in GetMediaProperty handling with enums and switch?
1894 enBTRCoreRet
1896  tBTRCoreAVMediaHdl hBTRCoreAVM,
1897  const char* apBtDevAddr,
1898  const char* mediaPropertyKey,
1899  void* mediaPropertyValue
1900 ) {
1901  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
1902  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
1903 
1904  if (!hBTRCoreAVM || !apBtDevAddr) {
1905  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
1906  return enBTRCoreInvalidArg;
1907  }
1908 
1909  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
1910 
1911  if (!pstlhBTRCoreAVM->pcAVMediaPlayerPath) {
1912  //TODO: The pcAVMediaPlayerPath changes during transition between Players on Smartphone (Local->Youtube->Local)
1913  // Seems to be the root cause of the stack corruption as part of DELIA-25861
1914  char* lpcAVMediaPlayerPath = BtrCore_BTGetMediaPlayerPath(pstlhBTRCoreAVM->btIfceHdl, apBtDevAddr);
1915  if (!lpcAVMediaPlayerPath || !(pstlhBTRCoreAVM->pcAVMediaPlayerPath = strndup(lpcAVMediaPlayerPath, BTRCORE_MAX_STR_LEN - 1))) {
1916  BTRCORELOG_ERROR ("Failed to get Media Player Object!!!");
1917  return enBTRCoreFailure;
1918  }
1919  }
1920 
1921  if (BtrCore_BTGetMediaPlayerProperty(pstlhBTRCoreAVM->btIfceHdl, pstlhBTRCoreAVM->pcAVMediaPlayerPath, mediaPropertyKey, mediaPropertyValue)) {
1922  BTRCORELOG_ERROR ("Failed to get Media Property : %s!!!",mediaPropertyKey);
1923  lenBTRCoreRet = enBTRCoreFailure;
1924  }
1925 
1926  return lenBTRCoreRet;
1927 }
1928 
1929 
1930 enBTRCoreRet
1932  tBTRCoreAVMediaHdl hBTRCoreAVM,
1933  const char* apBtDevAddr,
1934  tBTRCoreAVMediaElementId aBtrAVMediaElementId,
1935  eBTRCoreAVMElementType aeBtrAVMElementType
1936 ) {
1937  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
1938  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
1939  stBTRCoreAVMediaItem* ptr = NULL;
1940  const char* lpBtMediaFolderPath = NULL;
1941 
1942  if (!hBTRCoreAVM || !apBtDevAddr) {
1943  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
1944  return enBTRCoreInvalidArg;
1945  }
1946 
1947  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
1948 
1949  if (!pstlhBTRCoreAVM->pcAVMediaPlayerPath) {
1950  //TODO: The pcAVMediaPlayerPath changes during transition between Players on Smartphone (Local->Youtube->Local)
1951  // Seems to be the root cause of the stack corruption as part of DELIA-25861
1952  char* lpcAVMediaPlayerPath = BtrCore_BTGetMediaPlayerPath(pstlhBTRCoreAVM->btIfceHdl, apBtDevAddr);
1953  if (!lpcAVMediaPlayerPath || !(pstlhBTRCoreAVM->pcAVMediaPlayerPath = strndup(lpcAVMediaPlayerPath, BTRCORE_MAX_STR_LEN - 1))) {
1954  BTRCORELOG_ERROR ("Failed to get Media Player Object!!!");
1955  return enBTRCoreFailure;
1956  }
1957  }
1958 
1959  if (!pstlhBTRCoreAVM->pstAVMediaPlayer.m_mediaPlayerBrowsable) {
1960  BTRCORELOG_ERROR ("Connected Media is not Browsable!\n");
1961  return enBTRCoreFailure;
1962  }
1963 
1964 
1965  /* TODO Index based folderPath retrival */
1966  if (!(aBtrAVMediaElementId & BTR_MEDIA_PLAYLIST_ID)) {
1967 
1968  if ((ptr = pstlhBTRCoreAVM->pstAVMediaBrowser)) {
1969  /* If we are already on the same item */
1970  if (ptr->ui32AVMediaItemId == aBtrAVMediaElementId) {
1971  lpBtMediaFolderPath = ptr->pcAVMediaItemPath;
1972  }
1973  /* If the item is parent */
1974  if (!lpBtMediaFolderPath && ptr->pvAVMediaParentItem) {
1975  if (((stBTRCoreAVMediaItem*)(ptr->pvAVMediaParentItem))->ui32AVMediaItemId == aBtrAVMediaElementId) {
1976  lpBtMediaFolderPath = (char*)((stBTRCoreAVMediaItem*)(ptr->pvAVMediaParentItem))->pcAVMediaItemPath;
1977  ptr = ptr->pvAVMediaParentItem;
1978  }
1979  }
1980  /* If the item is one of the child */
1981  if (!lpBtMediaFolderPath) {
1982  if (ptr->ui32AVMediaNumberOfItems && ptr->pstAVMediaSubItems) {
1983  unsigned int ui32LoopIdx = 0;
1984 
1985  while (ui32LoopIdx < ptr->ui32AVMediaNumberOfItems) {
1986  if (ptr->pstAVMediaSubItems[ui32LoopIdx]->ui32AVMediaItemId == aBtrAVMediaElementId) {
1987  lpBtMediaFolderPath = ptr->pstAVMediaSubItems[ui32LoopIdx]->pcAVMediaItemPath;
1988  break;
1989  }
1990  ui32LoopIdx++;
1991  }
1992  }
1993  }
1994  /* Finding the shortest path from current location to destination */
1995  if (!lpBtMediaFolderPath) {
1996  while (ptr->pvAVMediaParentItem) {
1997  ptr = ptr->pvAVMediaParentItem;
1998  }
1999  /* Searching from root */
2000  if (!btrCore_AVMedia_FindMediaItem (ptr, aBtrAVMediaElementId, &ptr)) {
2001  /* on success ptr will be pointing the node which has mediaID as aBtrAVMediaElementId */
2002  if (ptr) {
2003  lpBtMediaFolderPath = ptr->pcAVMediaItemPath;
2004  if (btrCore_AVMedia_SwitchToMediaBrowserItem (pstlhBTRCoreAVM, ptr)) {
2005  BTRCORELOG_ERROR ("Switching to MediaBrowserItem(%llu) Failed!\n", ptr->ui32AVMediaItemId);
2006  lenBTRCoreRet = enBTRCoreFailure;
2007  }
2008  }
2009  else {
2010  BTRCORELOG_ERROR ("Media Item(%llu) Not Found!\n", aBtrAVMediaElementId);
2011  lenBTRCoreRet = enBTRCoreFailure;
2012  }
2013  }
2014  else {
2015  BTRCORELOG_ERROR ("Failed to Find Media Item(%llu) !\n", aBtrAVMediaElementId);
2016  lenBTRCoreRet = enBTRCoreFailure;
2017  }
2018  }
2019  }
2020  else {
2021  BTRCORELOG_ERROR ("Media Browser Error - No parent Filesystem !\n");
2022  lenBTRCoreRet = enBTRCoreFailure;
2023  }
2024  }
2025  else
2026  if (pstlhBTRCoreAVM->pstAVMediaPlayList) {
2027  lpBtMediaFolderPath = pstlhBTRCoreAVM->pstAVMediaPlayList->pcAVMediaItemPath;
2028  }
2029  else {
2030  BTRCORELOG_ERROR ("PlayList not found for Item : %llu !\n", aBtrAVMediaElementId);
2031  lenBTRCoreRet = enBTRCoreFailure;
2032  }
2033 
2034 
2035 
2036  if (!lpBtMediaFolderPath) {
2037  BTRCORELOG_ERROR ("Media Browser Error - cannot find item : %llu\n", aBtrAVMediaElementId);
2038  lenBTRCoreRet = enBTRCoreFailure;
2039  }
2040 
2041  if (lenBTRCoreRet == enBTRCoreSuccess &&
2042  BtrCore_BTChangeMediaFolder(pstlhBTRCoreAVM->btIfceHdl, pstlhBTRCoreAVM->pcAVMediaPlayerPath, lpBtMediaFolderPath)) {
2043  BTRCORELOG_ERROR ("Failed to change Browser Location to %s(%llu) !\n", lpBtMediaFolderPath, aBtrAVMediaElementId);
2044  lenBTRCoreRet = enBTRCoreFailure;
2045  }
2046 
2047  return lenBTRCoreRet;
2048 }
2049 
2050 
2051 enBTRCoreRet
2053  tBTRCoreAVMediaHdl hBTRCoreAVM,
2054  const char* apBtDevAddr,
2055  unsigned short aui16StartIdx,
2056  unsigned short aui16EndIdx
2057 ) {
2058  enBTRCoreRet lenBTRCoreRet = enBTRCoreSuccess;
2059  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
2060  unsigned int ui32NumberOfItems = 0;
2061 
2062  if (!hBTRCoreAVM || !apBtDevAddr) {
2063  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
2064  return enBTRCoreInvalidArg;
2065  }
2066 
2067  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
2068 
2069  if (!pstlhBTRCoreAVM->pcAVMediaPlayerPath) {
2070  //TODO: The pcAVMediaPlayerPath changes during transition between Players on Smartphone (Local->Youtube->Local)
2071  // Seems to be the root cause of the stack corruption as part of DELIA-25861
2072  char* lpcAVMediaPlayerPath = BtrCore_BTGetMediaPlayerPath(pstlhBTRCoreAVM->btIfceHdl, apBtDevAddr);
2073  if (!lpcAVMediaPlayerPath || !(pstlhBTRCoreAVM->pcAVMediaPlayerPath = strndup(lpcAVMediaPlayerPath, BTRCORE_MAX_STR_LEN - 1))) {
2074  BTRCORELOG_ERROR ("Failed to get Media Player Object!!!");
2075  return enBTRCoreFailure;
2076  }
2077  }
2078 
2079  if (!pstlhBTRCoreAVM->pstAVMediaPlayer.m_mediaPlayerBrowsable) {
2080  BTRCORELOG_ERROR ("Connected Media is not Browsable!\n");
2081  return enBTRCoreFailure;
2082  }
2083 
2084 
2085  if (!BtrCore_BTGetMediaFolderNumberOfItems (pstlhBTRCoreAVM->btIfceHdl, pstlhBTRCoreAVM->pcAVMediaPlayerPath, &ui32NumberOfItems)) {
2086  BTRCORELOG_DEBUG ("Number Of Items : %u\n", ui32NumberOfItems);
2087  if (ui32NumberOfItems && aui16EndIdx > ui32NumberOfItems) {
2088  aui16EndIdx = ui32NumberOfItems;
2089  }
2090  }
2091  else {
2092  BTRCORELOG_WARN ("Couldn't get No. Of Items in current Browser location!\n");
2093  }
2094 
2095  /*To enhance this logic better to handle failures too */
2096  if (aui16StartIdx <= aui16EndIdx) {
2097  BTRCORELOG_DEBUG ("Querying to list browser items from %u to %u\n", aui16StartIdx, aui16EndIdx);
2098 
2099  if (BtrCore_BTSelectMediaFolderItems (pstlhBTRCoreAVM->btIfceHdl, pstlhBTRCoreAVM->pcAVMediaPlayerPath, aui16StartIdx, aui16EndIdx, NULL, 0)) {
2100  BTRCORELOG_ERROR ("Failed to List Browser Items!\n");
2101  lenBTRCoreRet = enBTRCoreFailure;
2102  }
2103  }
2104  else {
2105  BTRCORELOG_ERROR ("List indices not in Range!\n");
2106  lenBTRCoreRet = enBTRCoreFailure;
2107  }
2108 
2109  { /* sleeping half of a second. Max 5 seconds */
2110  int ui32sleepIdx = 10;
2111 
2112  while (ui32sleepIdx-- && pstlhBTRCoreAVM->pstAVMediaPlayer.m_mediaBrowserItem->ui32AVMediaNumberOfItems < aui16EndIdx) {
2113  usleep (500000);
2114  }
2115  }
2116 
2117  return lenBTRCoreRet;
2118 }
2119 
2120 enBTRCoreRet
2122  tBTRCoreAVMediaHdl hBTRCoreAVM,
2123  const char* apBtDevAddr,
2124  tBTRCoreAVMediaElementId aBtrAVMediaElementId,
2125  unsigned short aui16StartIdx,
2126  unsigned short aui16EndIdx,
2127  eBTRCoreAVMElementType aeBtrAVMElementType,
2128  stBTRCoreAVMediaElementInfoList* aAVMediaElementInfoList
2129 ) {
2130  stBTRCoreAVMediaHdl* lpstlhBTRCoreAVM = NULL;
2131  stBTRCoreAVMediaItem* lpstBtAVMediaItem = NULL;
2132  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
2133 
2134  if (!hBTRCoreAVM || !apBtDevAddr || !aAVMediaElementInfoList ||
2135  aui16EndIdx < aui16StartIdx) {
2136  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
2137  return enBTRCoreInvalidArg;
2138  }
2139 
2140  if (aui16EndIdx - aui16StartIdx > BTR_AV_MEDIA_ELEMENT_MAX -1) {
2141  aui16EndIdx = aui16StartIdx + BTR_AV_MEDIA_ELEMENT_MAX -1;
2142  }
2143 
2144  lpstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
2145 
2146  if (!(lpstBtAVMediaItem = lpstlhBTRCoreAVM->pstAVMediaPlayer.m_mediaBrowserItem)) {
2147  BTRCORELOG_ERROR ("Media Browser Error - browsing handle is NULL!\n");
2148  return lenBTRCoreRet;
2149  }
2150 
2151  if (lpstBtAVMediaItem->ui32AVMediaItemId != aBtrAVMediaElementId) {
2152  stBTRCoreAVMediaItem* ptr = lpstlhBTRCoreAVM->pstAVMediaBrowser;
2153  BTRCORELOG_WARN ("Media Browser Error - Media ElementID(%llu) didn't match!\n", aBtrAVMediaElementId);
2154 
2155  if (ptr) {
2156  while (ptr->pvAVMediaParentItem) {
2157  ptr = ptr->pvAVMediaParentItem;
2158  }
2159 
2160  if (btrCore_AVMedia_FindMediaItem (ptr, aBtrAVMediaElementId, &lpstBtAVMediaItem)) {
2161  BTRCORELOG_ERROR ("Failed to Find MediaTrack by Id(%llu) !\n", aBtrAVMediaElementId);
2162  }
2163  }
2164  }
2165 
2166  if (!lpstBtAVMediaItem) {
2167  return lenBTRCoreRet;
2168  }
2169 
2170  if (lpstBtAVMediaItem->bIsMediaItemPlayable) {
2171  BTRCORELOG_ERROR ("Media Browser Error - Its a Playable Item!\n");
2172  return lenBTRCoreRet;
2173  }
2174 
2175  if (lpstBtAVMediaItem->pstAVMediaSubItems) {
2176  unsigned short m_numOfElements = 0;
2177 
2178  memset (aAVMediaElementInfoList, 0, sizeof(stBTRCoreAVMediaElementInfoList));
2179 
2180  while (aui16StartIdx <= aui16EndIdx && aui16StartIdx < lpstBtAVMediaItem->ui32AVMediaNumberOfItems && lpstBtAVMediaItem->pstAVMediaSubItems[aui16StartIdx]) {
2181 
2182  if ((aeBtrAVMElementType == eBTRCoreAVMETypeUnknown) || (aeBtrAVMElementType == lpstBtAVMediaItem->pstAVMediaSubItems[aui16StartIdx]->eMediaItemType)) {
2183  if (aeBtrAVMElementType == eBTRCoreAVMETypeUnknown) {
2184  aAVMediaElementInfoList->m_mediaElementInfo[m_numOfElements].eAVMElementType = eBTRCoreAVMETypeTrackList;
2185  }
2186  else {
2187  aAVMediaElementInfoList->m_mediaElementInfo[m_numOfElements].eAVMElementType = lpstBtAVMediaItem->eMediaItemType;
2188  }
2189 
2190  aAVMediaElementInfoList->m_mediaElementInfo[m_numOfElements].ui32AVMediaElementId = lpstBtAVMediaItem->pstAVMediaSubItems[aui16StartIdx]->ui32AVMediaItemId;
2191  aAVMediaElementInfoList->m_mediaElementInfo[m_numOfElements].bIsPlayable = lpstBtAVMediaItem->pstAVMediaSubItems[aui16StartIdx]->bIsMediaItemPlayable;
2192  strncpy(aAVMediaElementInfoList->m_mediaElementInfo[m_numOfElements].m_mediaElementName, lpstBtAVMediaItem->pstAVMediaSubItems[aui16StartIdx]->pcAVMediaItemName, BTRCORE_MAX_STR_LEN -1);
2193  memcpy (&aAVMediaElementInfoList->m_mediaElementInfo[m_numOfElements++].m_mediaTrackInfo, &lpstBtAVMediaItem->pstAVMediaSubItems[aui16StartIdx++]->mediaTrackInfo, sizeof(stBTRCoreAVMediaTrackInfo));
2194  }
2195  else {
2196  aui16StartIdx++;
2197  }
2198  }
2199  aAVMediaElementInfoList->m_numOfElements = m_numOfElements;
2200  lenBTRCoreRet = enBTRCoreSuccess;
2201  BTRCORELOG_INFO ("Number of MediaItems retrived : %d\n", aAVMediaElementInfoList->m_numOfElements);
2202  }
2203  else {
2204  BTRCORELOG_ERROR ("Media Browser Error - NumOfItems : %d | SubItems : %p\n", lpstBtAVMediaItem->ui32AVMediaNumberOfItems, lpstBtAVMediaItem->pstAVMediaSubItems);
2205  }
2206 
2207  return lenBTRCoreRet;
2208 }
2209 
2210 
2211 enBTRCoreRet
2213  tBTRCoreAVMediaHdl hBTRCoreAVM,
2214  const char* apBtDevAddr,
2215  tBTRCoreAVMediaElementId aBtrAVMediaItemId
2216 ) {
2217  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
2218  stBTRCoreAVMediaItem* ptrBsr = NULL;
2219  stBTRCoreAVMediaItem* ptrTrack = NULL;
2220  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
2221 
2222  if (!hBTRCoreAVM || !apBtDevAddr) {
2223  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
2224  return enBTRCoreInvalidArg;
2225  }
2226 
2227  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
2228 
2229 
2230  if (!(ptrBsr = (aBtrAVMediaItemId & BTR_MEDIA_PLAYLIST_ID)? pstlhBTRCoreAVM->pstAVMediaPlayList : pstlhBTRCoreAVM->pstAVMediaBrowser)) {
2231  BTRCORELOG_ERROR ("Media Browser doesn't exist!\n");
2232  return lenBTRCoreRet;
2233  }
2234 
2235  if (btrCore_AVMedia_FindMediaItem (ptrBsr, aBtrAVMediaItemId, &ptrTrack)) {
2236  BTRCORELOG_ERROR ("Failed to Search MediaTrack by Id(%llu) !\n", aBtrAVMediaItemId);
2237  return lenBTRCoreRet;
2238  }
2239 
2240  if (ptrTrack) {
2241  if (ptrTrack->bIsMediaItemPlayable) {
2242  if (ptrTrack->pcAVMediaItemPath[0]) {
2243  if (BtrCore_BTPlayMediaTrackItem (pstlhBTRCoreAVM->btIfceHdl, ptrTrack->pcAVMediaItemPath)) {
2244  BTRCORELOG_ERROR ("Failed to Play Media Track Item(%llu) %s !\n", aBtrAVMediaItemId, ptrTrack->pcAVMediaItemPath);
2245  }
2246  else {
2247  lenBTRCoreRet = enBTRCoreSuccess;
2248  }
2249  }
2250  else {
2251  BTRCORELOG_ERROR ("Media Item Path is not present!\n");
2252  }
2253  }
2254  else {
2255  BTRCORELOG_ERROR ("Media Item %llu is not Playable!\n", aBtrAVMediaItemId);
2256  }
2257  }
2258  else {
2259  BTRCORELOG_ERROR ("Media Track Item(%llu) not found!\n", aBtrAVMediaItemId);
2260  }
2261 
2262  return lenBTRCoreRet;
2263 }
2264 
2265 
2266 enBTRCoreRet
2268  tBTRCoreAVMediaHdl hBTRCoreAVM,
2269  const char* apBtDevAddr,
2270  tBTRCoreAVMediaElementId aBtrAVMediaItemId
2271 ) {
2272  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
2273  stBTRCoreAVMediaItem* ptrBsr = NULL;
2274  stBTRCoreAVMediaItem* ptrTrack = NULL;
2275  stBTRCoreAVMediaTrackInfo apstBTAVMediaTrackInfo;
2276  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
2277 
2278  if (!hBTRCoreAVM || !apBtDevAddr) {
2279  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
2280  return enBTRCoreInvalidArg;
2281  }
2282 
2283  BTRCORELOG_DEBUG (" SetTrack Entered \n");
2284  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
2285 
2286  if (!(ptrBsr = (aBtrAVMediaItemId & BTR_MEDIA_PLAYLIST_ID)? pstlhBTRCoreAVM->pstAVMediaPlayList : pstlhBTRCoreAVM->pstAVMediaBrowser)) {
2287  BTRCORELOG_ERROR ("Media Browser doesn't exist!\n");
2288  return lenBTRCoreRet;
2289  }
2290 
2291  if (btrCore_AVMedia_FindMediaItem (ptrBsr, aBtrAVMediaItemId, &ptrTrack)) {
2292  BTRCORELOG_ERROR ("Failed to Search MediaTrack by Id(%llu) !\n", aBtrAVMediaItemId);
2293  return lenBTRCoreRet;
2294  }
2295 
2296 
2297  if (ptrTrack) {
2298  if (ptrTrack->bIsMediaItemPlayable) {
2299  if (ptrTrack->pcAVMediaItemPath[0]) {
2300  if(BtrCore_BTGetTrackInformation(pstlhBTRCoreAVM->btIfceHdl,
2301  ptrTrack->pcAVMediaItemPath, (stBTMediaTrackInfo*)&apstBTAVMediaTrackInfo))
2302  {
2303  BTRCORELOG_ERROR ("Failed to get media info!!!");
2304  lenBTRCoreRet = enBTRCoreFailure;
2305  } else {
2306  pstlhBTRCoreAVM->SelectedaBtrAVMediaItemId = aBtrAVMediaItemId;
2307  memset(&pstlhBTRCoreAVM->SelectedapstBTAVMediaTrackInfo, 0, sizeof(stBTRCoreAVMediaTrackInfo));
2308  memcpy(&pstlhBTRCoreAVM->SelectedapstBTAVMediaTrackInfo, &apstBTAVMediaTrackInfo, sizeof(stBTRCoreAVMediaTrackInfo));
2309  BTRCORELOG_DEBUG (" Get track info success ");
2310  lenBTRCoreRet = enBTRCoreSuccess;
2311  }
2312  }
2313  else {
2314  BTRCORELOG_ERROR ("Media Item Path is not present!\n");
2315  }
2316  }
2317  else {
2318  BTRCORELOG_ERROR ("Media Item %llu is not Playable!\n", aBtrAVMediaItemId);
2319  }
2320  }
2321  else {
2322  BTRCORELOG_ERROR ("Media Track Item(%llu) not found!\n", aBtrAVMediaItemId);
2323  }
2324 
2325  return lenBTRCoreRet;
2326 }
2327 
2328 
2329 enBTRCoreRet
2331  tBTRCoreAVMediaHdl hBTRCoreAVM,
2332  const char* apBtDevAddr,
2333  tBTRCoreAVMediaElementId aBtrAVMediaItemId,
2334  char* isPlayable
2335 ) {
2336  stBTRCoreAVMediaHdl* lpstlhBTRCoreAVM = NULL;
2337  stBTRCoreAVMediaItem* lpstBtAVMBrowser = NULL;
2338  stBTRCoreAVMediaItem* lpstBtAVMItem = NULL;
2339  enBTRCoreRet lenBTRCoreRet = enBTRCoreFailure;
2340 
2341  if (!hBTRCoreAVM || !apBtDevAddr) {
2342  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
2343  return enBTRCoreInvalidArg;
2344  }
2345 
2346  lpstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
2347 
2348 
2349  if (aBtrAVMediaItemId & BTR_MEDIA_PLAYLIST_ID) {
2350  lpstBtAVMBrowser = lpstlhBTRCoreAVM->pstAVMediaPlayList;
2351  }
2352  else {
2353  lpstBtAVMBrowser = lpstlhBTRCoreAVM->pstAVMediaBrowser;
2354  while (lpstBtAVMBrowser->pvAVMediaParentItem) {
2355  lpstBtAVMBrowser = lpstBtAVMBrowser->pvAVMediaParentItem;
2356  }
2357  }
2358 
2359  if (!lpstBtAVMBrowser) {
2360  BTRCORELOG_ERROR ("Media Browser doesn't exist!\n");
2361  return lenBTRCoreRet;
2362  }
2363 
2364  if (btrCore_AVMedia_FindMediaItem (lpstBtAVMBrowser, aBtrAVMediaItemId, &lpstBtAVMItem)) {
2365  BTRCORELOG_ERROR ("Failed to Search MediaTrack by Id(%llu) !\n", aBtrAVMediaItemId);
2366  return lenBTRCoreRet;
2367  }
2368 
2369  if (lpstBtAVMItem) {
2370  if ((*isPlayable = lpstBtAVMItem->bIsMediaItemPlayable)) {
2371  BTRCORELOG_DEBUG ("Its a playable Media Item\n");
2372  }
2373  else {
2374  BTRCORELOG_DEBUG ("Its a non-playable Media Item\n");
2375  }
2376  lenBTRCoreRet = enBTRCoreSuccess;
2377  }
2378  else {
2379  BTRCORELOG_ERROR ("Media Item(%llu) not found!\n", aBtrAVMediaItemId);
2380  }
2381 
2382 
2383  return lenBTRCoreRet;
2384 }
2385 
2386 // Outgoing callbacks Registration Interfaces
2387 enBTRCoreRet
2389  tBTRCoreAVMediaHdl hBTRCoreAVM,
2390  fPtr_BTRCore_AVMediaStatusUpdateCb afpcBBTRCoreAVMediaStatusUpdate,
2391  void* apvBMediaStatusUserData
2392 ) {
2393  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
2394 
2395  if (!hBTRCoreAVM || !afpcBBTRCoreAVMediaStatusUpdate) {
2396  BTRCORELOG_ERROR ("enBTRCoreInvalidArg\n");
2397  return enBTRCoreInvalidArg;
2398  }
2399 
2400  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)hBTRCoreAVM;
2401 
2402  pstlhBTRCoreAVM->fpcBBTRCoreAVMediaStatusUpdate = afpcBBTRCoreAVMediaStatusUpdate;
2403  pstlhBTRCoreAVM->pcBMediaStatusUserData = apvBMediaStatusUserData;
2404 
2405  return enBTRCoreSuccess;
2406 }
2407 
2408 
2409 /* Incoming Callbacks */
2410 static int
2411 btrCore_AVMedia_NegotiateMediaCb (
2412  void* apBtMediaCapsInput,
2413  void** appBtMediaCapsOutput,
2414  enBTDeviceType aenBTDeviceType,
2415  enBTMediaType aenBTMediaType,
2416  void* apUserData
2417 ) {
2418  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
2419 
2420  if (!apBtMediaCapsInput) {
2421  BTRCORELOG_ERROR ("Invalid input MT Media Capabilities\n");
2422  return -1;
2423  }
2424 
2425  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)apUserData;
2426 
2427 
2428  if (aenBTMediaType == enBTMediaTypeSBC) {
2429  a2dp_sbc_t* apBtMediaSBCCaps = (a2dp_sbc_t*)apBtMediaCapsInput;
2430  a2dp_sbc_t lstBTMediaSbcConfig;
2431 
2432  memset(&lstBTMediaSbcConfig, 0, sizeof(a2dp_sbc_t));
2433 
2434 #if 0
2435  lstBTMediaSbcConfig.frequency = pstlhBTRCoreAVM->iBTMediaDefSampFreqPref;
2436 #else
2437  if (apBtMediaSBCCaps->frequency & BTR_SBC_SAMPLING_FREQ_48000) {
2438  lstBTMediaSbcConfig.frequency = BTR_SBC_SAMPLING_FREQ_48000;
2439  }
2440  else if (apBtMediaSBCCaps->frequency & BTR_SBC_SAMPLING_FREQ_44100) {
2441  lstBTMediaSbcConfig.frequency = BTR_SBC_SAMPLING_FREQ_44100;
2442  }
2443  else if (apBtMediaSBCCaps->frequency & BTR_SBC_SAMPLING_FREQ_32000) {
2444  lstBTMediaSbcConfig.frequency = BTR_SBC_SAMPLING_FREQ_32000;
2445  }
2446  else if (apBtMediaSBCCaps->frequency & BTR_SBC_SAMPLING_FREQ_16000) {
2447  lstBTMediaSbcConfig.frequency = BTR_SBC_SAMPLING_FREQ_16000;
2448  }
2449  else {
2450  BTRCORELOG_ERROR ("No supported frequency\n");
2451  return -1;
2452  }
2453 #endif
2454 
2455  if (apBtMediaSBCCaps->channel_mode & BTR_SBC_CHANNEL_MODE_JOINT_STEREO) {
2456  lstBTMediaSbcConfig.channel_mode = BTR_SBC_CHANNEL_MODE_JOINT_STEREO;
2457  }
2458  else if (apBtMediaSBCCaps->channel_mode & BTR_SBC_CHANNEL_MODE_STEREO) {
2459  lstBTMediaSbcConfig.channel_mode = BTR_SBC_CHANNEL_MODE_STEREO;
2460  }
2461  else if (apBtMediaSBCCaps->channel_mode & BTR_SBC_CHANNEL_MODE_DUAL_CHANNEL) {
2462  lstBTMediaSbcConfig.channel_mode = BTR_SBC_CHANNEL_MODE_DUAL_CHANNEL;
2463  }
2464  else if (apBtMediaSBCCaps->channel_mode & BTR_SBC_CHANNEL_MODE_MONO) {
2465  lstBTMediaSbcConfig.channel_mode = BTR_SBC_CHANNEL_MODE_MONO;
2466  }
2467  else {
2468  BTRCORELOG_ERROR ("No supported channel modes\n");
2469  return -1;
2470  }
2471 
2472  if (apBtMediaSBCCaps->block_length & BTR_SBC_BLOCK_LENGTH_16) {
2473  lstBTMediaSbcConfig.block_length = BTR_SBC_BLOCK_LENGTH_16;
2474  }
2475  else if (apBtMediaSBCCaps->block_length & BTR_SBC_BLOCK_LENGTH_12) {
2476  lstBTMediaSbcConfig.block_length = BTR_SBC_BLOCK_LENGTH_12;
2477  }
2478  else if (apBtMediaSBCCaps->block_length & BTR_SBC_BLOCK_LENGTH_8) {
2479  lstBTMediaSbcConfig.block_length = BTR_SBC_BLOCK_LENGTH_8;
2480  }
2481  else if (apBtMediaSBCCaps->block_length & BTR_SBC_BLOCK_LENGTH_4) {
2482  lstBTMediaSbcConfig.block_length = BTR_SBC_BLOCK_LENGTH_4;
2483  }
2484  else {
2485  BTRCORELOG_ERROR ("No supported block lengths\n");
2486  return -1;
2487  }
2488 
2489  if (apBtMediaSBCCaps->subbands & BTR_SBC_SUBBANDS_8) {
2490  lstBTMediaSbcConfig.subbands = BTR_SBC_SUBBANDS_8;
2491  }
2492  else if (apBtMediaSBCCaps->subbands & BTR_SBC_SUBBANDS_4) {
2493  lstBTMediaSbcConfig.subbands = BTR_SBC_SUBBANDS_4;
2494  }
2495  else {
2496  BTRCORELOG_ERROR ("No supported subbands\n");
2497  return -1;
2498  }
2499 
2500  if (apBtMediaSBCCaps->allocation_method & BTR_SBC_ALLOCATION_LOUDNESS) {
2501  lstBTMediaSbcConfig.allocation_method = BTR_SBC_ALLOCATION_LOUDNESS;
2502  }
2503  else if (apBtMediaSBCCaps->allocation_method & BTR_SBC_ALLOCATION_SNR) {
2504  lstBTMediaSbcConfig.allocation_method = BTR_SBC_ALLOCATION_SNR;
2505  }
2506 
2507  lstBTMediaSbcConfig.min_bitpool = (uint8_t) MAX(MIN_BITPOOL, apBtMediaSBCCaps->min_bitpool);
2508  lstBTMediaSbcConfig.max_bitpool = (uint8_t) MIN(btrCore_AVMedia_GetA2DPDefaultBitpool(lstBTMediaSbcConfig.frequency,
2509  lstBTMediaSbcConfig.channel_mode),
2510  apBtMediaSBCCaps->max_bitpool);
2511 
2512  BTRCORELOG_TRACE("Negotiated Configuration\n");
2513  BTRCORELOG_INFO ("channel_mode = %d\n", lstBTMediaSbcConfig.channel_mode);
2514  BTRCORELOG_INFO ("frequency = %d\n", lstBTMediaSbcConfig.frequency);
2515  BTRCORELOG_INFO ("allocation_method = %d\n", lstBTMediaSbcConfig.allocation_method);
2516  BTRCORELOG_INFO ("subbands = %d\n", lstBTMediaSbcConfig.subbands);
2517  BTRCORELOG_INFO ("block_length = %d\n", lstBTMediaSbcConfig.block_length);
2518  BTRCORELOG_INFO ("min_bitpool = %d\n", lstBTMediaSbcConfig.min_bitpool);
2519  BTRCORELOG_INFO ("max_bitpool = %d\n", lstBTMediaSbcConfig.max_bitpool);
2520 
2521  if (pstlhBTRCoreAVM) {
2522  a2dp_sbc_t* lpstBTAVMMediaSbcConfigOut = (a2dp_sbc_t*)pstlhBTRCoreAVM->pstBTMediaConfigOut;
2523  a2dp_sbc_t* lpstBTAVMMediaSbcConfigIn = (a2dp_sbc_t*)pstlhBTRCoreAVM->pstBTMediaConfigIn;
2524 
2525  if (lpstBTAVMMediaSbcConfigOut &&
2526  (aenBTDeviceType == enBTDevAudioSink) &&
2527  (pstlhBTRCoreAVM->eAVMediaTypeOut != eBTRCoreAVMTypeSBC)) {
2528  pstlhBTRCoreAVM->eAVMediaTypeOut = eBTRCoreAVMTypeSBC;
2529  lpstBTAVMMediaSbcConfigOut->channel_mode = lstBTMediaSbcConfig.channel_mode;
2530  lpstBTAVMMediaSbcConfigOut->frequency = lstBTMediaSbcConfig.frequency;
2531  lpstBTAVMMediaSbcConfigOut->allocation_method = lstBTMediaSbcConfig.allocation_method;
2532  lpstBTAVMMediaSbcConfigOut->subbands = lstBTMediaSbcConfig.subbands;
2533  lpstBTAVMMediaSbcConfigOut->block_length = lstBTMediaSbcConfig.block_length;
2534  lpstBTAVMMediaSbcConfigOut->min_bitpool = lstBTMediaSbcConfig.min_bitpool;
2535  lpstBTAVMMediaSbcConfigOut->max_bitpool = lstBTMediaSbcConfig.max_bitpool;
2536 
2537  *appBtMediaCapsOutput = (void*)lpstBTAVMMediaSbcConfigOut;
2538  }
2539 
2540  if (lpstBTAVMMediaSbcConfigIn &&
2541  (aenBTDeviceType == enBTDevAudioSource) &&
2542  (pstlhBTRCoreAVM->eAVMediaTypeIn != eBTRCoreAVMTypeSBC)) {
2543  pstlhBTRCoreAVM->eAVMediaTypeIn = eBTRCoreAVMTypeSBC;
2544  lpstBTAVMMediaSbcConfigIn->channel_mode = lstBTMediaSbcConfig.channel_mode;
2545  lpstBTAVMMediaSbcConfigIn->frequency = lstBTMediaSbcConfig.frequency;
2546  lpstBTAVMMediaSbcConfigIn->allocation_method = lstBTMediaSbcConfig.allocation_method;
2547  lpstBTAVMMediaSbcConfigIn->subbands = lstBTMediaSbcConfig.subbands;
2548  lpstBTAVMMediaSbcConfigIn->block_length = lstBTMediaSbcConfig.block_length;
2549  lpstBTAVMMediaSbcConfigIn->min_bitpool = lstBTMediaSbcConfig.min_bitpool;
2550  lpstBTAVMMediaSbcConfigIn->max_bitpool = lstBTMediaSbcConfig.max_bitpool;
2551 
2552  *appBtMediaCapsOutput = (void*)lpstBTAVMMediaSbcConfigIn;
2553  }
2554  }
2555  }
2556  else if (aenBTMediaType == enBTMediaTypePCM) {
2557 
2558  }
2559  else if (aenBTMediaType == enBTMediaTypeAAC) {
2560 #if defined(AAC_SUPPORTED)
2561  a2dp_aac_t* apBtMediaAACCaps = (a2dp_aac_t*)apBtMediaCapsInput;
2562  a2dp_aac_t lstBTMediaAacConfig;
2563  unsigned short ui16AacInFreq = 0;
2564  unsigned short ui16AacOutFreq = 0;
2565  unsigned short ui16AacInBitrate= 0;
2566  unsigned short ui16AacOutBitrate= 0;
2567 
2568  memset(&lstBTMediaAacConfig, 0, sizeof(a2dp_aac_t));
2569 
2570  ui16AacInFreq = BTR_AAC_GET_FREQ(*apBtMediaAACCaps);
2571  if (ui16AacInFreq & BTR_AAC_SAMPLING_FREQ_8000) {
2572  ui16AacOutFreq = BTR_AAC_SAMPLING_FREQ_8000;
2573  }
2574  else if (ui16AacInFreq & BTR_AAC_SAMPLING_FREQ_11025) {
2575  ui16AacOutFreq = BTR_AAC_SAMPLING_FREQ_11025;
2576  }
2577  else if (ui16AacInFreq & BTR_AAC_SAMPLING_FREQ_12000) {
2578  ui16AacOutFreq = BTR_AAC_SAMPLING_FREQ_12000;
2579  }
2580  else if (ui16AacInFreq & BTR_AAC_SAMPLING_FREQ_16000) {
2581  ui16AacOutFreq = BTR_AAC_SAMPLING_FREQ_16000;
2582  }
2583  else if (ui16AacInFreq & BTR_AAC_SAMPLING_FREQ_22050) {
2584  ui16AacOutFreq = BTR_AAC_SAMPLING_FREQ_22050;
2585  }
2586  else if (ui16AacInFreq & BTR_AAC_SAMPLING_FREQ_24000) {
2587  ui16AacOutFreq = BTR_AAC_SAMPLING_FREQ_24000;
2588  }
2589  else if (ui16AacInFreq & BTR_AAC_SAMPLING_FREQ_32000) {
2590  ui16AacOutFreq = BTR_AAC_SAMPLING_FREQ_32000;
2591  }
2592  else if (ui16AacInFreq & BTR_AAC_SAMPLING_FREQ_44100) {
2593  ui16AacOutFreq = BTR_AAC_SAMPLING_FREQ_44100;
2594  }
2595  else if (ui16AacInFreq & BTR_AAC_SAMPLING_FREQ_48000) {
2596  ui16AacOutFreq = BTR_AAC_SAMPLING_FREQ_48000;
2597  }
2598  else if (ui16AacInFreq & BTR_AAC_SAMPLING_FREQ_64000) {
2599  ui16AacOutFreq = BTR_AAC_SAMPLING_FREQ_64000;
2600  }
2601  else if (ui16AacInFreq & BTR_AAC_SAMPLING_FREQ_88200) {
2602  ui16AacOutFreq = BTR_AAC_SAMPLING_FREQ_88200;
2603  }
2604  else if (ui16AacInFreq & BTR_AAC_SAMPLING_FREQ_96000) {
2605  ui16AacOutFreq = BTR_AAC_SAMPLING_FREQ_96000;
2606  }
2607  else {
2608  BTRCORELOG_ERROR ("No supported frequency\n");
2609  return -1;
2610  }
2611 
2612  BTR_AAC_SET_FREQ(lstBTMediaAacConfig, ui16AacOutFreq);
2613 
2614  ui16AacInBitrate = BTR_AAC_GET_BITRATE(*apBtMediaAACCaps);
2615  if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_VBR) {
2616  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_VBR;
2617  }
2618  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_320000) {
2619  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_320000;
2620  }
2621  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_256000) {
2622  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_256000;
2623  }
2624  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_224000) {
2625  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_224000;
2626  }
2627  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_192000) {
2628  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_192000;
2629  }
2630  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_160000) {
2631  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_160000;
2632  }
2633  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_128000) {
2634  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_128000;
2635  }
2636  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_112000) {
2637  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_112000;
2638  }
2639  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_96000) {
2640  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_96000;
2641  }
2642  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_80000) {
2643  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_80000;
2644  }
2645  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_64000) {
2646  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_64000;
2647  }
2648  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_56000) {
2649  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_56000;
2650  }
2651  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_48000) {
2652  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_48000;
2653  }
2654  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_40000) {
2655  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_40000;
2656  }
2657  else if (ui16AacInBitrate & BTR_MPEG_BIT_RATE_32000) {
2658  ui16AacOutBitrate = BTR_MPEG_BIT_RATE_32000;
2659  }
2660  else {
2661  BTRCORELOG_ERROR ("No supported bitrate\n");
2662  return -1;
2663  }
2664 
2665  BTR_AAC_SET_BITRATE(lstBTMediaAacConfig, ui16AacOutBitrate);
2666 
2667 
2668  if (apBtMediaAACCaps->object_type & BTR_AAC_OT_MPEG2_AAC_LC) {
2669  lstBTMediaAacConfig.object_type = BTR_AAC_OT_MPEG2_AAC_LC;
2670  }
2671  else if (apBtMediaAACCaps->object_type & BTR_AAC_OT_MPEG4_AAC_LC) {
2672  lstBTMediaAacConfig.object_type = BTR_AAC_OT_MPEG4_AAC_LC;
2673  }
2674  else if (apBtMediaAACCaps->object_type & BTR_AAC_OT_MPEG4_AAC_LTP) {
2675  lstBTMediaAacConfig.object_type = BTR_AAC_OT_MPEG4_AAC_LTP;
2676  }
2677  else if (apBtMediaAACCaps->object_type & BTR_AAC_OT_MPEG4_AAC_SCA) {
2678  lstBTMediaAacConfig.object_type = BTR_AAC_OT_MPEG4_AAC_SCA;
2679  }
2680  else {
2681  BTRCORELOG_ERROR ("No supported aac object type\n");
2682  return -1;
2683  }
2684 
2685 
2686  if (apBtMediaAACCaps->channels & BTR_AAC_CHANNELS_1) {
2687  lstBTMediaAacConfig.channels = BTR_AAC_CHANNELS_1;
2688  }
2689  else if (apBtMediaAACCaps->channels & BTR_AAC_CHANNELS_2) {
2690  lstBTMediaAacConfig.channels = BTR_AAC_CHANNELS_2;
2691  }
2692  else {
2693  BTRCORELOG_ERROR ("No supported aac channel\n");
2694  return -1;
2695  }
2696 
2697  lstBTMediaAacConfig.vbr = apBtMediaAACCaps->vbr;
2698  lstBTMediaAacConfig.rfa = apBtMediaAACCaps->rfa;
2699 
2700 
2701  BTRCORELOG_TRACE("Negotiated Configuration\n");
2702  BTRCORELOG_INFO ("object_type = %d\n", lstBTMediaAacConfig.object_type);
2703  BTRCORELOG_INFO ("frequency1 = %d\n", lstBTMediaAacConfig.frequency1);
2704  BTRCORELOG_INFO ("rfa = %d\n", lstBTMediaAacConfig.rfa);
2705  BTRCORELOG_INFO ("channels = %d\n", lstBTMediaAacConfig.channels);
2706  BTRCORELOG_INFO ("frequency2 = %d\n", lstBTMediaAacConfig.frequency2);
2707  BTRCORELOG_INFO ("bitrate1 = %d\n", lstBTMediaAacConfig.bitrate1);
2708  BTRCORELOG_INFO ("vbr = %d\n", lstBTMediaAacConfig.vbr);
2709  BTRCORELOG_INFO ("bitrate2 = %d\n", lstBTMediaAacConfig.bitrate2);
2710  BTRCORELOG_INFO ("bitrate3 = %d\n", lstBTMediaAacConfig.bitrate3);
2711 
2712  if (pstlhBTRCoreAVM) {
2713  a2dp_aac_t* lpstBTAVMMediaAacConfigOut = (a2dp_aac_t*)pstlhBTRCoreAVM->pstBTMediaConfigOut;
2714  a2dp_aac_t* lpstBTAVMMediaAacConfigIn = (a2dp_aac_t*)pstlhBTRCoreAVM->pstBTMediaConfigIn;
2715 
2716  if (lpstBTAVMMediaAacConfigOut &&
2717  (aenBTDeviceType == enBTDevAudioSink) &&
2718  (pstlhBTRCoreAVM->eAVMediaTypeOut != eBTRCoreAVMTypeAAC)) {
2719  pstlhBTRCoreAVM->eAVMediaTypeOut = eBTRCoreAVMTypeAAC;
2720  lpstBTAVMMediaAacConfigOut->object_type = lstBTMediaAacConfig.object_type;
2721  lpstBTAVMMediaAacConfigOut->frequency1 = lstBTMediaAacConfig.frequency1;
2722  lpstBTAVMMediaAacConfigOut->rfa = lstBTMediaAacConfig.rfa;
2723  lpstBTAVMMediaAacConfigOut->channels = lstBTMediaAacConfig.channels;
2724  lpstBTAVMMediaAacConfigOut->frequency2 = lstBTMediaAacConfig.frequency2;
2725  lpstBTAVMMediaAacConfigOut->bitrate1 = lstBTMediaAacConfig.bitrate1;
2726  lpstBTAVMMediaAacConfigOut->vbr = lstBTMediaAacConfig.vbr;
2727  lpstBTAVMMediaAacConfigOut->bitrate2 = lstBTMediaAacConfig.bitrate2;
2728  lpstBTAVMMediaAacConfigOut->bitrate3 = lstBTMediaAacConfig.bitrate3;
2729 
2730  *appBtMediaCapsOutput = (void*)lpstBTAVMMediaAacConfigOut;
2731  }
2732 
2733  if (lpstBTAVMMediaAacConfigIn &&
2734  (aenBTDeviceType == enBTDevAudioSource) &&
2735  (pstlhBTRCoreAVM->eAVMediaTypeIn != eBTRCoreAVMTypeAAC)) {
2736  pstlhBTRCoreAVM->eAVMediaTypeIn = eBTRCoreAVMTypeAAC;
2737  lpstBTAVMMediaAacConfigIn->object_type = lstBTMediaAacConfig.object_type;
2738  lpstBTAVMMediaAacConfigIn->frequency1 = lstBTMediaAacConfig.frequency1;
2739  lpstBTAVMMediaAacConfigIn->rfa = lstBTMediaAacConfig.rfa;
2740  lpstBTAVMMediaAacConfigIn->channels = lstBTMediaAacConfig.channels;
2741  lpstBTAVMMediaAacConfigIn->frequency2 = lstBTMediaAacConfig.frequency2;
2742  lpstBTAVMMediaAacConfigIn->bitrate1 = lstBTMediaAacConfig.bitrate1;
2743  lpstBTAVMMediaAacConfigIn->vbr = lstBTMediaAacConfig.vbr;
2744  lpstBTAVMMediaAacConfigIn->bitrate2 = lstBTMediaAacConfig.bitrate2;
2745  lpstBTAVMMediaAacConfigIn->bitrate3 = lstBTMediaAacConfig.bitrate3;
2746 
2747  *appBtMediaCapsOutput = (void*)lpstBTAVMMediaAacConfigIn;
2748  }
2749  }
2750 #endif
2751  }
2752  else if (aenBTMediaType == enBTMediaTypeMP3) {
2753 
2754  }
2755 
2756  return *appBtMediaCapsOutput ? 0 : -1;
2757 }
2758 
2759 
2760 static int
2761 btrCore_AVMedia_TransportPathCb (
2762  const char* apBtMediaTransportPath,
2763  const char* apBtMediaUuid,
2764  void* apBtMediaCaps,
2765  enBTDeviceType aenBTDeviceType,
2766  enBTMediaType aenBTMediaType,
2767  void* apUserData
2768 ) {
2769  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
2770  int i32BtRet = -1;
2771 
2772  if (!apBtMediaTransportPath) {
2773  BTRCORELOG_ERROR ("Invalid transport path\n");
2774  return -1;
2775  }
2776 
2777  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)apUserData;
2778 
2779  if (apBtMediaCaps && apBtMediaUuid) {
2780  if (aenBTMediaType == enBTMediaTypeSBC) {
2781  a2dp_sbc_t* apBtMediaSBCCaps = NULL;
2782  a2dp_sbc_t lstBTMediaSbcConfig;
2783 
2784  apBtMediaSBCCaps = (a2dp_sbc_t*)apBtMediaCaps;
2785 
2786  lstBTMediaSbcConfig.channel_mode = apBtMediaSBCCaps->channel_mode;
2787  lstBTMediaSbcConfig.frequency = apBtMediaSBCCaps->frequency;
2788  lstBTMediaSbcConfig.allocation_method = apBtMediaSBCCaps->allocation_method;
2789  lstBTMediaSbcConfig.subbands = apBtMediaSBCCaps->subbands;
2790  lstBTMediaSbcConfig.block_length = apBtMediaSBCCaps->block_length;
2791 
2792  if (apBtMediaSBCCaps->min_bitpool == MIN_BITPOOL)
2793  lstBTMediaSbcConfig.min_bitpool = (uint8_t) MAX(MIN_BITPOOL, apBtMediaSBCCaps->min_bitpool);
2794  else
2795  lstBTMediaSbcConfig.min_bitpool = apBtMediaSBCCaps->min_bitpool;
2796 
2797  if (apBtMediaSBCCaps->max_bitpool == MAX_BITPOOL)
2798  lstBTMediaSbcConfig.max_bitpool = (uint8_t) MIN(btrCore_AVMedia_GetA2DPDefaultBitpool(lstBTMediaSbcConfig.frequency,
2799  lstBTMediaSbcConfig.channel_mode),
2800  apBtMediaSBCCaps->max_bitpool);
2801  else
2802  lstBTMediaSbcConfig.max_bitpool = apBtMediaSBCCaps->max_bitpool;
2803 
2804  BTRCORELOG_TRACE("Set Configuration\n");
2805  BTRCORELOG_INFO ("channel_mode = %d\n", lstBTMediaSbcConfig.channel_mode);
2806  BTRCORELOG_INFO ("frequency = %d\n", lstBTMediaSbcConfig.frequency);
2807  BTRCORELOG_INFO ("allocation_method = %d\n", lstBTMediaSbcConfig.allocation_method);
2808  BTRCORELOG_INFO ("subbands = %d\n", lstBTMediaSbcConfig.subbands);
2809  BTRCORELOG_INFO ("block_length = %d\n", lstBTMediaSbcConfig.block_length);
2810  BTRCORELOG_INFO ("min_bitpool = %d\n", lstBTMediaSbcConfig.min_bitpool);
2811  BTRCORELOG_INFO ("max_bitpool = %d\n", lstBTMediaSbcConfig.max_bitpool);
2812 
2813  //TODO: Best possible Generic solution for DELIA-23555 at this moment
2814  // Async nature of lower layer bt-ifce stack i.e. bluez session call enters an invalid
2815  // state as the reference to the session with the device is completely unreffered when we
2816  // return too quickly from the callback which results in the crash at bluez is an open is still
2817  // pending at bluez from the device
2818  // Delaying the return to bluez results in the session being unreffed with delay and the
2819  // incoming open from the device on avdtp to be processed as we have not returrned and there
2820  // is a valid ref in bluez
2821  sleep(1);
2822 
2823  if (pstlhBTRCoreAVM) {
2824  a2dp_sbc_t* lpstBTAVMMediaSbcConfig = NULL;
2825 
2826  if (!strncmp(apBtMediaUuid, BT_UUID_A2DP_SOURCE, strlen(BT_UUID_A2DP_SOURCE))) {
2827  lpstBTAVMMediaSbcConfig = pstlhBTRCoreAVM->pstBTMediaConfigOut;
2828  pstlhBTRCoreAVM->eAVMediaTypeOut = eBTRCoreAVMTypeSBC;
2829 
2830  BTRCORELOG_INFO ("max_bitpool Incoming = %d Stored/Calculated = %d\n", lstBTMediaSbcConfig.max_bitpool, lpstBTAVMMediaSbcConfig->max_bitpool);
2831  if (lstBTMediaSbcConfig.frequency == BTR_SBC_SAMPLING_FREQ_44100) {
2832  /* Reuse - Negotiated lpstBTAVMMediaSbcConfig->max_bitpool */
2833  lpstBTAVMMediaSbcConfig->frequency = BTR_SBC_SAMPLING_FREQ_48000;
2834  }
2835  else {
2836  lpstBTAVMMediaSbcConfig->frequency = lstBTMediaSbcConfig.frequency;
2837  }
2838 
2839  if (apBtMediaSBCCaps->max_bitpool == MAX_BITPOOL) {
2840  lpstBTAVMMediaSbcConfig->max_bitpool = (uint8_t) MIN(btrCore_AVMedia_GetA2DPDefaultBitpool(lpstBTAVMMediaSbcConfig->frequency,
2841  lstBTMediaSbcConfig.channel_mode),
2842  apBtMediaSBCCaps->max_bitpool);
2843  }
2844  else if (lstBTMediaSbcConfig.max_bitpool < lpstBTAVMMediaSbcConfig->max_bitpool) {
2845  lpstBTAVMMediaSbcConfig->max_bitpool = lstBTMediaSbcConfig.max_bitpool;
2846  }
2847  }
2848  else if (!strncmp(apBtMediaUuid, BT_UUID_A2DP_SINK, strlen(BT_UUID_A2DP_SINK))) {
2849  lpstBTAVMMediaSbcConfig = pstlhBTRCoreAVM->pstBTMediaConfigIn;
2850  pstlhBTRCoreAVM->eAVMediaTypeIn = eBTRCoreAVMTypeSBC;
2851  lpstBTAVMMediaSbcConfig->frequency = lstBTMediaSbcConfig.frequency;
2852  lpstBTAVMMediaSbcConfig->max_bitpool= lstBTMediaSbcConfig.max_bitpool;
2853  }
2854  else {
2855  lpstBTAVMMediaSbcConfig = pstlhBTRCoreAVM->pstBTMediaConfigOut;
2856  pstlhBTRCoreAVM->eAVMediaTypeOut = eBTRCoreAVMTypeSBC;
2857  if (lstBTMediaSbcConfig.frequency == BTR_SBC_SAMPLING_FREQ_44100) {
2858  /* Reuse - Negotiated lpstBTAVMMediaSbcConfig->max_bitpool */
2859  lpstBTAVMMediaSbcConfig->frequency = BTR_SBC_SAMPLING_FREQ_48000;
2860  }
2861  else {
2862  lpstBTAVMMediaSbcConfig->frequency = lstBTMediaSbcConfig.frequency;
2863  }
2864 
2865  if (apBtMediaSBCCaps->max_bitpool == MAX_BITPOOL) {
2866  lpstBTAVMMediaSbcConfig->max_bitpool = (uint8_t) MIN(btrCore_AVMedia_GetA2DPDefaultBitpool(lpstBTAVMMediaSbcConfig->frequency,
2867  lstBTMediaSbcConfig.channel_mode),
2868  apBtMediaSBCCaps->max_bitpool);
2869  }
2870  else if (lstBTMediaSbcConfig.max_bitpool < lpstBTAVMMediaSbcConfig->max_bitpool) {
2871  lpstBTAVMMediaSbcConfig->max_bitpool = lstBTMediaSbcConfig.max_bitpool;
2872  }
2873  }
2874 
2875  if (lpstBTAVMMediaSbcConfig) {
2876  lpstBTAVMMediaSbcConfig->channel_mode = lstBTMediaSbcConfig.channel_mode;
2877  lpstBTAVMMediaSbcConfig->allocation_method = lstBTMediaSbcConfig.allocation_method;
2878  lpstBTAVMMediaSbcConfig->subbands = lstBTMediaSbcConfig.subbands;
2879  lpstBTAVMMediaSbcConfig->block_length = lstBTMediaSbcConfig.block_length;
2880  lpstBTAVMMediaSbcConfig->min_bitpool = lstBTMediaSbcConfig.min_bitpool;
2881  i32BtRet = 0;
2882  }
2883  }
2884  }
2885  else if (aenBTMediaType == enBTMediaTypePCM) {
2886 
2887  }
2888  else if (aenBTMediaType == enBTMediaTypeAAC) {
2889 #if defined(AAC_SUPPORTED)
2890  a2dp_aac_t* apBtMediaAACCaps = NULL;
2891  a2dp_aac_t lstBTMediaAacConfig;
2892 
2893  apBtMediaAACCaps = (a2dp_aac_t*)apBtMediaCaps;
2894 
2895  lstBTMediaAacConfig.object_type = apBtMediaAACCaps->object_type;
2896  lstBTMediaAacConfig.frequency1 = apBtMediaAACCaps->frequency1;
2897  lstBTMediaAacConfig.rfa = apBtMediaAACCaps->rfa;
2898  lstBTMediaAacConfig.channels = apBtMediaAACCaps->channels;
2899  lstBTMediaAacConfig.frequency2 = apBtMediaAACCaps->frequency2;
2900  lstBTMediaAacConfig.bitrate1 = apBtMediaAACCaps->bitrate1;
2901  lstBTMediaAacConfig.vbr = apBtMediaAACCaps->vbr;
2902  lstBTMediaAacConfig.bitrate2 = apBtMediaAACCaps->bitrate2;
2903  lstBTMediaAacConfig.bitrate3 = apBtMediaAACCaps->bitrate3;
2904 
2905  BTRCORELOG_TRACE("Set Configuration\n");
2906  BTRCORELOG_INFO ("object_type = %d\n", lstBTMediaAacConfig.object_type);
2907  BTRCORELOG_INFO ("frequency1 = %d\n", lstBTMediaAacConfig.frequency1);
2908  BTRCORELOG_INFO ("rfa = %d\n", lstBTMediaAacConfig.rfa);
2909  BTRCORELOG_INFO ("channels = %d\n", lstBTMediaAacConfig.channels);
2910  BTRCORELOG_INFO ("frequency2 = %d\n", lstBTMediaAacConfig.frequency2);
2911  BTRCORELOG_INFO ("bitrate1 = %d\n", lstBTMediaAacConfig.bitrate1);
2912  BTRCORELOG_INFO ("vbr = %d\n", lstBTMediaAacConfig.vbr);
2913  BTRCORELOG_INFO ("bitrate2 = %d\n", lstBTMediaAacConfig.bitrate2);
2914  BTRCORELOG_INFO ("bitrate3 = %d\n", lstBTMediaAacConfig.bitrate3);
2915 
2916  //TODO: Best possible Generic solution for DELIA-23555 at this moment
2917  sleep(1);
2918 
2919  if (pstlhBTRCoreAVM) {
2920  a2dp_aac_t* lpstBTAVMMediaAacConfig = NULL;
2921 
2922  if (!strncmp(apBtMediaUuid, BT_UUID_A2DP_SOURCE, strlen(BT_UUID_A2DP_SOURCE))) {
2923  lpstBTAVMMediaAacConfig = pstlhBTRCoreAVM->pstBTMediaConfigOut;
2924  pstlhBTRCoreAVM->eAVMediaTypeOut= eBTRCoreAVMTypeAAC;
2925  }
2926  else if (!strncmp(apBtMediaUuid, BT_UUID_A2DP_SINK, strlen(BT_UUID_A2DP_SINK))) {
2927  lpstBTAVMMediaAacConfig = pstlhBTRCoreAVM->pstBTMediaConfigIn;
2928  pstlhBTRCoreAVM->eAVMediaTypeIn = eBTRCoreAVMTypeAAC;
2929  }
2930  else {
2931  lpstBTAVMMediaAacConfig = pstlhBTRCoreAVM->pstBTMediaConfigOut;
2932  pstlhBTRCoreAVM->eAVMediaTypeOut= eBTRCoreAVMTypeAAC;
2933  }
2934 
2935  if (lpstBTAVMMediaAacConfig) {
2936  lpstBTAVMMediaAacConfig->object_type = lstBTMediaAacConfig.object_type;
2937  lpstBTAVMMediaAacConfig->frequency1 = lstBTMediaAacConfig.frequency1;
2938  lpstBTAVMMediaAacConfig->rfa = lstBTMediaAacConfig.rfa;
2939  lpstBTAVMMediaAacConfig->channels = lstBTMediaAacConfig.channels;
2940  lpstBTAVMMediaAacConfig->frequency2 = lstBTMediaAacConfig.frequency2;
2941  lpstBTAVMMediaAacConfig->bitrate1 = lstBTMediaAacConfig.bitrate1;
2942  lpstBTAVMMediaAacConfig->vbr = lstBTMediaAacConfig.vbr;
2943  lpstBTAVMMediaAacConfig->bitrate2 = lstBTMediaAacConfig.bitrate2;
2944  lpstBTAVMMediaAacConfig->bitrate3 = lstBTMediaAacConfig.bitrate3;
2945  i32BtRet = 0;
2946  }
2947  }
2948 #endif
2949  }
2950  else if (aenBTMediaType == enBTMediaTypeMP3) {
2951 
2952  }
2953  }
2954  else {
2955  a2dp_sbc_t lstBtA2dpSbcCaps;
2956  lstBtA2dpSbcCaps.channel_mode = BTR_SBC_CHANNEL_MODE_MONO | BTR_SBC_CHANNEL_MODE_DUAL_CHANNEL |
2957  BTR_SBC_CHANNEL_MODE_STEREO | BTR_SBC_CHANNEL_MODE_JOINT_STEREO;
2958  lstBtA2dpSbcCaps.frequency = BTR_SBC_SAMPLING_FREQ_16000 | BTR_SBC_SAMPLING_FREQ_32000 |
2959  BTR_SBC_SAMPLING_FREQ_44100 | BTR_SBC_SAMPLING_FREQ_48000;
2960  lstBtA2dpSbcCaps.allocation_method = BTR_SBC_ALLOCATION_SNR | BTR_SBC_ALLOCATION_LOUDNESS;
2961  lstBtA2dpSbcCaps.subbands = BTR_SBC_SUBBANDS_4 | BTR_SBC_SUBBANDS_8;
2962  lstBtA2dpSbcCaps.block_length = BTR_SBC_BLOCK_LENGTH_4 | BTR_SBC_BLOCK_LENGTH_8 |
2963  BTR_SBC_BLOCK_LENGTH_12 | BTR_SBC_BLOCK_LENGTH_16;
2964  lstBtA2dpSbcCaps.min_bitpool = MIN_BITPOOL;
2965  lstBtA2dpSbcCaps.max_bitpool = MAX_BITPOOL;
2966 
2967  if (pstlhBTRCoreAVM) {
2968  void* lpstBTAVMMediaConfig = NULL;
2969 
2970  if (pstlhBTRCoreAVM->pcAVMediaTransportPathOut) {
2971  if(!strncmp(pstlhBTRCoreAVM->pcAVMediaTransportPathOut, apBtMediaTransportPath, strlen(pstlhBTRCoreAVM->pcAVMediaTransportPathOut))) {
2972  BTRCORELOG_INFO ("Freeing %p:%s\n", pstlhBTRCoreAVM->pcAVMediaTransportPathOut, pstlhBTRCoreAVM->pcAVMediaTransportPathOut);
2973 
2974  free(pstlhBTRCoreAVM->pcAVMediaTransportPathOut);
2975  pstlhBTRCoreAVM->pcAVMediaTransportPathOut = NULL;
2976  pstlhBTRCoreAVM->eAVMediaTypeOut = eBTRCoreAVMTypeUnknown;
2977 
2978  lpstBTAVMMediaConfig = pstlhBTRCoreAVM->pstBTMediaConfigOut;
2979  i32BtRet = 0;
2980 
2981  if (lpstBTAVMMediaConfig) {
2982  BTRCORELOG_TRACE("Retain Media Configuration\n");
2983  /* memcpy(lpstBTAVMMediaConfig, &lstBtA2dpSbcCaps, sizeof(a2dp_sbc_t)); */
2984  /* Ensure that last connected Audio-Out device uses Negotiated Media Config on PowerOff-PowerOn */
2985  }
2986  }
2987  }
2988 
2989  if (pstlhBTRCoreAVM->pcAVMediaTransportPathIn) {
2990  if(!strncmp(pstlhBTRCoreAVM->pcAVMediaTransportPathIn, apBtMediaTransportPath, strlen(pstlhBTRCoreAVM->pcAVMediaTransportPathIn))) {
2991  BTRCORELOG_INFO ("Freeing %p:%s\n", pstlhBTRCoreAVM->pcAVMediaTransportPathIn, pstlhBTRCoreAVM->pcAVMediaTransportPathIn);
2992 
2993  free(pstlhBTRCoreAVM->pcAVMediaTransportPathIn);
2994  pstlhBTRCoreAVM->pcAVMediaTransportPathIn = NULL;
2995  pstlhBTRCoreAVM->eAVMediaTypeIn = eBTRCoreAVMTypeUnknown;
2996 
2997  lpstBTAVMMediaConfig = pstlhBTRCoreAVM->pstBTMediaConfigIn;
2998  i32BtRet = 0;
2999 
3000  if (lpstBTAVMMediaConfig) {
3001  BTRCORELOG_TRACE("Reset Media Configuration\n");
3002  memcpy(lpstBTAVMMediaConfig, &lstBtA2dpSbcCaps, sizeof(a2dp_sbc_t));
3003  }
3004  }
3005  }
3006 
3007  }
3008  }
3009 
3010 
3011  if (pstlhBTRCoreAVM) {
3012  if (apBtMediaUuid && !strncmp(apBtMediaUuid, BT_UUID_A2DP_SOURCE, strlen(BT_UUID_A2DP_SOURCE))) {
3013  if (pstlhBTRCoreAVM->pcAVMediaTransportPathOut) {
3014  if(!strncmp(pstlhBTRCoreAVM->pcAVMediaTransportPathOut, apBtMediaTransportPath, strlen(pstlhBTRCoreAVM->pcAVMediaTransportPathOut))) {
3015  BTRCORELOG_ERROR ("Freeing %p:%s - Unexpected\n", pstlhBTRCoreAVM->pcAVMediaTransportPathOut, pstlhBTRCoreAVM->pcAVMediaTransportPathOut);
3016  i32BtRet = 0;
3017  }
3018 
3019  free(pstlhBTRCoreAVM->pcAVMediaTransportPathOut);
3020  pstlhBTRCoreAVM->pcAVMediaTransportPathOut = NULL;
3021  }
3022  else {
3023  pstlhBTRCoreAVM->pcAVMediaTransportPathOut = strndup(apBtMediaTransportPath, BTRCORE_MAX_STR_LEN - 1);
3024  }
3025  }
3026  else if (apBtMediaUuid && !strncmp(apBtMediaUuid, BT_UUID_A2DP_SINK, strlen(BT_UUID_A2DP_SINK))) {
3027  if (pstlhBTRCoreAVM->pcAVMediaTransportPathIn) {
3028  if(!strncmp(pstlhBTRCoreAVM->pcAVMediaTransportPathIn, apBtMediaTransportPath, strlen(pstlhBTRCoreAVM->pcAVMediaTransportPathIn))) {
3029  BTRCORELOG_ERROR ("Freeing %p:%s - Unexpected\n", pstlhBTRCoreAVM->pcAVMediaTransportPathIn, pstlhBTRCoreAVM->pcAVMediaTransportPathIn);
3030  i32BtRet = 0;
3031  }
3032 
3033  free(pstlhBTRCoreAVM->pcAVMediaTransportPathIn);
3034  pstlhBTRCoreAVM->pcAVMediaTransportPathIn = NULL;
3035  }
3036  else {
3037  pstlhBTRCoreAVM->pcAVMediaTransportPathIn = strndup(apBtMediaTransportPath, BTRCORE_MAX_STR_LEN - 1);
3038  }
3039  }
3040  }
3041 
3042 
3043  return i32BtRet;
3044 }
3045 
3046 
3047 static int
3048 btrCore_AVMedia_MediaPlayerPathCb (
3049  const char* apcBTMediaPlayerPath,
3050  void* apUserData
3051 ) {
3052  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
3053  int i32BtRet = -1;
3054 
3055  if (!apcBTMediaPlayerPath) {
3056  BTRCORELOG_ERROR ("Invalid media path\n");
3057  return i32BtRet;
3058  }
3059 
3060  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)apUserData;
3061 
3062  if (pstlhBTRCoreAVM) {
3063  if (pstlhBTRCoreAVM->pcAVMediaPlayerPath) {
3064  char* ptr = pstlhBTRCoreAVM->pcAVMediaPlayerPath;
3065 
3066  if (!strncmp(pstlhBTRCoreAVM->pcAVMediaPlayerPath, apcBTMediaPlayerPath,
3067  (strlen(pstlhBTRCoreAVM->pcAVMediaPlayerPath) > strlen(apcBTMediaPlayerPath)) ? strlen(pstlhBTRCoreAVM->pcAVMediaPlayerPath) : strlen(apcBTMediaPlayerPath))) {
3068  BTRCORELOG_INFO ("Freeing %p:%s\n", pstlhBTRCoreAVM->pcAVMediaPlayerPath, pstlhBTRCoreAVM->pcAVMediaPlayerPath);
3069 
3070  pstlhBTRCoreAVM->pcAVMediaPlayerPath = NULL;
3071  free(ptr);
3072  }
3073  else {
3074  BTRCORELOG_INFO ("Switching Media Player from %s to %s\n", pstlhBTRCoreAVM->pcAVMediaPlayerPath, apcBTMediaPlayerPath);
3075  pstlhBTRCoreAVM->pcAVMediaPlayerPath = strndup(apcBTMediaPlayerPath, BTRCORE_MAX_STR_LEN - 1);
3076  free(ptr);
3077  /*TODO At here, we should initiallize 'pstAVMediaPlayer' properties as the player has changed effectively */
3078  memset (&pstlhBTRCoreAVM->pstAVMediaPlayer, 0, sizeof(pstlhBTRCoreAVM->pstAVMediaPlayer));
3079  strncpy (pstlhBTRCoreAVM->pstAVMediaPlayer.m_mediaPlayerName, "UnknownPlayer", BTRCORE_MAX_STR_LEN -1);
3080  }
3081  }
3082  else {
3083  BTRCORELOG_INFO ("Storing Media Player : %s\n", apcBTMediaPlayerPath);
3084  pstlhBTRCoreAVM->pcAVMediaPlayerPath = strndup(apcBTMediaPlayerPath, BTRCORE_MAX_STR_LEN - 1);
3085  }
3086  i32BtRet = 0;
3087  }
3088 
3089  return i32BtRet;
3090 }
3091 
3092 
3093 /*implemented specific to StreamIn case, as it seems for StreamOut case that
3094  with idle, pending and active transport states can't predict the actual media stream state */
3095 static int
3096 btrCore_AVMedia_MediaStatusUpdateCb (
3097  enBTDeviceType aeBtDeviceType,
3098  stBTMediaStatusUpdate* apstBtMediaStUpdate,
3099  const char* apcBtDevAddr,
3100  void* apUserData
3101 ) {
3102  stBTRCoreAVMediaStatusUpdate mediaStatus;
3103  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
3104  BOOLEAN postEvent = FALSE;
3105  int i32BtRet = 0;
3106 
3107  if (!apcBtDevAddr || !apstBtMediaStUpdate || !apUserData) {
3108  BTRCORELOG_ERROR ("enBTRCoreInvalidArg!!!\n");
3109  return -1;
3110  }
3111  BTRCORELOG_DEBUG ("AV Media Status Cb\n");
3112 
3113  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)apUserData;
3114 
3115 
3116  switch (apstBtMediaStUpdate->aenBtOpIfceType) {
3117  case enBTMediaTransport:
3118 
3119  switch (apstBtMediaStUpdate->aunBtOpIfceProp.enBtMediaTransportProp) {
3120  case enBTMedTPropState:
3121 
3122  switch (apstBtMediaStUpdate->m_mediaTransportState) {
3123  case enBTMedTransportStIdle:
3124  pstlhBTRCoreAVM->eAVMTState = enAVMTransportStDisconnected;
3125  break;
3126  case enBTMedTransportStPending:
3127  pstlhBTRCoreAVM->eAVMTState = enAVMTransportStToBeConnected;
3128  break;
3129  case enBTMedTransportStActive:
3130  pstlhBTRCoreAVM->eAVMTState = enAVMTransportStConnected;
3131  break;
3132  default:
3133  break;
3134  }
3135  BTRCORELOG_DEBUG ("AV Media Transport State : %d\n", pstlhBTRCoreAVM->eAVMTState);
3136  break;
3137 
3138  case enBTMedTPropVol:
3139  mediaStatus.eAVMediaState = eBTRCoreAVMediaPlyrVolume;
3140  mediaStatus.bIsAVMediaCtrlAvail = pstlhBTRCoreAVM->bAVMediaPlayerConnected;
3141  mediaStatus.m_mediaPlayerTransportVolume = apstBtMediaStUpdate->m_mediaTransportVolume;
3142  pstlhBTRCoreAVM->ui8AVMediaTransportVolume = apstBtMediaStUpdate->m_mediaTransportVolume;
3143  pstlhBTRCoreAVM->bAVMediaTrVolAvrcp = TRUE;
3144  BTRCORELOG_DEBUG ("AV Media Transport Volume : %d%%\n", pstlhBTRCoreAVM->ui8AVMediaTransportVolume);
3145  postEvent = TRUE;
3146  break;
3147  default:
3148  break;
3149  }
3150  break;
3151 
3152  case enBTMediaControl:
3153 
3154  switch (apstBtMediaStUpdate->aunBtOpIfceProp.enBtMediaControlProp) {
3155  case enBTMedControlPropConnected:
3156  if (enBTDevAudioSource == aeBtDeviceType) {
3157  if (apstBtMediaStUpdate->m_mediaPlayerConnected) {
3158  /* Among If-Added, Property-MediaPlayerConnected & Property-MediaPlayerPath CBs, lets use
3159  * the Property-MediaPlayerConnected CB to spwan playback position polling thread as it is
3160  * the last signal and a complete confirmation of readiness of the bottom layer.
3161  */
3162  if (!(pstlhBTRCoreAVM->bAVMediaPlayerConnected || pstlhBTRCoreAVM->pMediaPollingThread)) {
3164  memset (pstAVMediaStUserData, 0, sizeof(stBTRCoreAVMediaStatusUserData));
3165  memset (&pstlhBTRCoreAVM->pstAVMediaPlayer, 0, sizeof(stBTRCoreAVMediaPlayer));
3166  strncpy (pstlhBTRCoreAVM->pstAVMediaPlayer.m_mediaPlayerName, "UnknownPlayer", BTRCORE_MAX_STR_LEN -1);
3167 
3168  pstAVMediaStUserData->apvAVMUserData = pstlhBTRCoreAVM->btIfceHdl; //TODO: This is redundant. There should be no need to do this
3169  pstAVMediaStUserData->apcAVMDevAddress = strndup(apcBtDevAddr, BTRCORE_MAX_STR_LEN - 1);
3170 
3171  pstlhBTRCoreAVM->pvThreadData = (void*)pstAVMediaStUserData;
3172 
3173  pstlhBTRCoreAVM->pMediaPollingThread = g_thread_new ("btrCore_AVMedia_PlaybackPositionPolling", btrCore_AVMedia_PlaybackPositionPolling, (void*)(pstlhBTRCoreAVM));
3174 
3175  if (!pstlhBTRCoreAVM->pMediaPollingThread) {
3176  BTRCORELOG_ERROR ("Failed to thread create btrCore_AVMedia_PlaybackPositionPolling");
3177  i32BtRet = -1;
3178  }
3179  }
3180  else {
3181  BTRCORELOG_WARN ("btrCore_AVMedia_PlaybackPositionPolling thread is running already!!!");
3182  }
3183  }
3184  else {
3185  if (pstlhBTRCoreAVM->pstAVMediaBrowser || pstlhBTRCoreAVM->pstAVMediaPlayList ||
3186  pstlhBTRCoreAVM->ui32AVMediaBrowserItemCount || pstlhBTRCoreAVM->ui32AVMediaPlayListItemCount) {
3187  BTRCORELOG_WARN ("Media Browser Error - ####### Possibility Of Memory Leak #####\n");
3188  BTRCORELOG_WARN ("Media Browser Error - MediaBrowser : %p(%u) | MediaPlayList : %p(%u)\n"
3189  , pstlhBTRCoreAVM->pstAVMediaBrowser
3190  , pstlhBTRCoreAVM->ui32AVMediaBrowserItemCount
3191  , pstlhBTRCoreAVM->pstAVMediaPlayList
3192  , pstlhBTRCoreAVM->ui32AVMediaPlayListItemCount);
3193 
3194  if (pstlhBTRCoreAVM->pstAVMediaBrowser) {
3195  while (pstlhBTRCoreAVM->pstAVMediaBrowser->pvAVMediaParentItem) {
3196  pstlhBTRCoreAVM->pstAVMediaBrowser = pstlhBTRCoreAVM->pstAVMediaBrowser->pvAVMediaParentItem;
3197  }
3198  if (!btrCore_AVMedia_DeallocateUnhandledBrowserMemory (pstlhBTRCoreAVM, apcBtDevAddr, &pstlhBTRCoreAVM->pstAVMediaBrowser)) {
3199  BTRCORELOG_ERROR ("Media Browser Error - Deallocate Unhandled Browser Memory Failed!\n");
3200  }
3201  pstlhBTRCoreAVM->pstAVMediaBrowser = NULL;
3202  }
3203 
3204  if (pstlhBTRCoreAVM->pstAVMediaPlayList) {
3205  if (!btrCore_AVMedia_DeallocateUnhandledBrowserMemory (pstlhBTRCoreAVM, apcBtDevAddr, &pstlhBTRCoreAVM->pstAVMediaPlayList)) {
3206  BTRCORELOG_ERROR ("Media Browser Error - Deallocate Unhandled Browser Memory Failed!\n");
3207  }
3208  pstlhBTRCoreAVM->pstAVMediaPlayList = NULL;
3209  }
3210 
3211  pstlhBTRCoreAVM->ui32AVMediaBrowserItemCount = 0;
3212  pstlhBTRCoreAVM->ui32AVMediaPlayListItemCount = 0;
3213  }
3214 
3215  if (pstlhBTRCoreAVM->bAVMediaPlayerConnected && pstlhBTRCoreAVM->pMediaPollingThread) {
3216  /* Exit playback position polling thread */
3217  pstlhBTRCoreAVM->pstAVMediaPlayer.eAVMediaStatusUpdate = eBTRCoreAVMediaPlaybackEnded;
3218  g_thread_join (pstlhBTRCoreAVM->pMediaPollingThread);
3219 
3220  if (pstlhBTRCoreAVM->pvThreadData) {
3221  if (((stBTRCoreAVMediaStatusUserData*)pstlhBTRCoreAVM->pvThreadData)->apcAVMDevAddress) {
3222  free ((void*)((stBTRCoreAVMediaStatusUserData*)pstlhBTRCoreAVM->pvThreadData)->apcAVMDevAddress);
3223  }
3224  free (pstlhBTRCoreAVM->pvThreadData);
3225  pstlhBTRCoreAVM->pvThreadData = NULL;
3226  }
3227  pstlhBTRCoreAVM->pMediaPollingThread = NULL;
3228  pstlhBTRCoreAVM->eAVMTState = enAVMTransportStDisconnected;
3229 
3230  BTRCORELOG_INFO ("Successfully Exited Media Position Polling Thread\n");
3231 
3232  /* Lets look for a better place inorder to be in sync with the bottom layer */
3233  if (pstlhBTRCoreAVM->pcAVMediaPlayerPath) {
3234  BTRCORELOG_INFO ("Freeing %p:%s\n", pstlhBTRCoreAVM->pcAVMediaPlayerPath, pstlhBTRCoreAVM->pcAVMediaPlayerPath);
3235  free (pstlhBTRCoreAVM->pcAVMediaPlayerPath);
3236  pstlhBTRCoreAVM->pcAVMediaPlayerPath = NULL;
3237  }
3238  }
3239  else {
3240  BTRCORELOG_ERROR ("pstlhBTRCoreAVM->pMediaPollingThread doesn't exists!!!");
3241  i32BtRet = -1;
3242  }
3243  }
3244  pstlhBTRCoreAVM->bAVMediaPlayerConnected = apstBtMediaStUpdate->m_mediaPlayerConnected;
3245  }
3246  else {
3247  pstlhBTRCoreAVM->bAVMediaPlayerConnected = apstBtMediaStUpdate->m_mediaPlayerConnected;
3248  pstlhBTRCoreAVM->pcAVMediaControlPath = strndup(apcBtDevAddr, BTRCORE_MAX_STR_LEN - 1);
3249  BTRCORELOG_DEBUG ("Device Type : %d Control Path : %s\n", aeBtDeviceType, pstlhBTRCoreAVM->pcAVMediaControlPath);
3250  }
3251 
3252  BTRCORELOG_DEBUG ("AV Media Player Connected : %s - %d\n", apcBtDevAddr, apstBtMediaStUpdate->m_mediaPlayerConnected);
3253  break;
3254 
3255  case enBTMedControlPropPath:
3256  BTRCORELOG_DEBUG ("AV Media Player connected Path : %s\n", apstBtMediaStUpdate->m_mediaPlayerPath);
3257  break;
3258  default:
3259  break;
3260  }
3261  break;
3262 
3263  case enBTMediaPlayer:
3264  {
3265  stBTRCoreAVMediaPlayer* lstAVMediaPlayer = &pstlhBTRCoreAVM->pstAVMediaPlayer;
3266 
3267  switch (apstBtMediaStUpdate->aunBtOpIfceProp.enBtMediaPlayerProp) {
3268  case enBTMedPlayerPropName:
3269  mediaStatus.eAVMediaState = eBTRCoreAVMediaPlyrName;
3270  strncpy(lstAVMediaPlayer->m_mediaPlayerName, apstBtMediaStUpdate->m_mediaPlayerName, BTRCORE_MAX_STR_LEN - 1);
3271  strncpy(mediaStatus.m_mediaPlayerName, lstAVMediaPlayer->m_mediaPlayerName, BTRCORE_MAX_STR_LEN - 1);
3272  BTRCORELOG_DEBUG ("AV Media Player Name : %s\n", lstAVMediaPlayer->m_mediaPlayerName);
3273  postEvent = TRUE;
3274  break;
3275 
3276  case enBTMedPlayerPropType:
3277  switch (apstBtMediaStUpdate->enMediaPlayerType) {
3278  case enBTMedPlayerTypAudio:
3279  lstAVMediaPlayer->eAVMediaPlayerType = eBTRCoreAVMPTypAudio;
3280  break;
3281  case enBTMedPlayerTypVideo:
3282  lstAVMediaPlayer->eAVMediaPlayerType = eBTRCoreAVMPTypVideo;
3283  break;
3284  case enBTMedPlayerTypAudioBroadcasting:
3285  lstAVMediaPlayer->eAVMediaPlayerType = eBTRCoreAVMPTypAudioBroadcasting;
3286  break;
3287  case enBTMedPlayerTypVideoBroadcasting:
3288  lstAVMediaPlayer->eAVMediaPlayerType = eBTRCoreAVMPTypVideoBroadcasting;
3289  break;
3290  default:
3291  lstAVMediaPlayer->eAVMediaPlayerType = eBTRCoreAVMPTypUnknown;
3292  }
3293  BTRCORELOG_DEBUG ("AV Media Player Type : %d\n", lstAVMediaPlayer->eAVMediaPlayerType);
3294  break;
3295 
3296  case enBTMedPlayerPropSubtype:
3297  switch (apstBtMediaStUpdate->enMediaPlayerSubtype) {
3298  case enBTMedPlayerSbTypAudioBook:
3299  lstAVMediaPlayer->eAVMediaPlayerSubtype = eBTRCoreAVMPSbTypAudioBook;
3300  break;
3301  case enBTMedPlayerSbTypPodcast:
3302  lstAVMediaPlayer->eAVMediaPlayerSubtype = eBTRCoreAVMPSbTypPodcast;
3303  break;
3304  default:
3305  lstAVMediaPlayer->eAVMediaPlayerSubtype = eBTRCoreAVMPSbTypUnknown;
3306  }
3307  BTRCORELOG_DEBUG ("AV Media Player Subtype : %d\n", lstAVMediaPlayer->eAVMediaPlayerSubtype);
3308  break;
3309 
3310  case enBTMedPlayerPropTrack:
3311  mediaStatus.eAVMediaState = eBTRCoreAVMediaTrkStChanged;
3312  lstAVMediaPlayer->m_mediaTrackChanged = 1;
3313 
3314  /* As per the analysed results, property 'Duration' alone may get updated seperately apart from the entire Track Info.
3315  This behavior of bluez along with UUID=0* for certain song items lead to this issue of replacing the TrackInfo at
3316  bluez layer with only Duration info. Thus a TrackInfo Query to bluez will fetch only Duration or the last updated.
3317  Hence the below logic is framed to store TrackInfo in our DB only if we have a valid 'Title'** val. Else our stack
3318  will interpret it as a Duration update(which is occuring quite frequently, which caused RDK-23133).
3319  * - UUID!=0 for song item will create a iface for it at bluez layer, hence any updation will persist entire TrkInfo.
3320  - UUID==0 for song item will not create a iface and its Trk details are stored in bluez's MP Track which will be
3321  overwritten by any further updates.
3322  ** - 'Title' property has been choosed as a key here, since it contains value for sure, even when album/artist/Genre
3323  could be empty(as per observations). And it didn't show any updatation within a song's scope.
3324  */
3325  if (apstBtMediaStUpdate->m_mediaTrackInfo.pcTitle[0]) {
3326  memset(&lstAVMediaPlayer->m_mediaTrackInfo, 0, sizeof(stBTRCoreAVMediaTrackInfo));
3327  memcpy(&lstAVMediaPlayer->m_mediaTrackInfo, &apstBtMediaStUpdate->m_mediaTrackInfo, sizeof(stBTRCoreAVMediaTrackInfo));
3328  } else {
3329  if (!apstBtMediaStUpdate->m_mediaTrackInfo.pcAlbum[0] && !apstBtMediaStUpdate->m_mediaTrackInfo.pcArtist[0] &&
3330  !apstBtMediaStUpdate->m_mediaTrackInfo.pcGenre[0] && !apstBtMediaStUpdate->m_mediaTrackInfo.ui32Duration) {
3331  strncpy (apstBtMediaStUpdate->m_mediaTrackInfo.pcTitle,
3332  strncpy (apstBtMediaStUpdate->m_mediaTrackInfo.pcArtist,
3333  strncpy (apstBtMediaStUpdate->m_mediaTrackInfo.pcAlbum,
3334  strncpy (apstBtMediaStUpdate->m_mediaTrackInfo.pcGenre, "Unknown", BTRCORE_MAX_STR_LEN -1),
3335  BTRCORE_MAX_STR_LEN -1),
3336  BTRCORE_MAX_STR_LEN -1),
3337  BTRCORE_MAX_STR_LEN -1);
3338  }
3339 
3340  if (apstBtMediaStUpdate->m_mediaTrackInfo.ui32Duration) {
3341  lstAVMediaPlayer->m_mediaTrackInfo.ui32Duration = apstBtMediaStUpdate->m_mediaTrackInfo.ui32Duration;
3342  }
3343  if (apstBtMediaStUpdate->m_mediaTrackInfo.pcArtist[0]) {
3344  strncpy (lstAVMediaPlayer->m_mediaTrackInfo.pcArtist, apstBtMediaStUpdate->m_mediaTrackInfo.pcArtist, BTRCORE_MAX_STR_LEN - 1);
3345  }
3346  if (apstBtMediaStUpdate->m_mediaTrackInfo.pcAlbum[0]) {
3347  strncpy (lstAVMediaPlayer->m_mediaTrackInfo.pcAlbum, apstBtMediaStUpdate->m_mediaTrackInfo.pcAlbum, BTRCORE_MAX_STR_LEN - 1);
3348  }
3349  if (apstBtMediaStUpdate->m_mediaTrackInfo.pcGenre[0]) {
3350  strncpy (lstAVMediaPlayer->m_mediaTrackInfo.pcGenre, apstBtMediaStUpdate->m_mediaTrackInfo.pcGenre, BTRCORE_MAX_STR_LEN - 1);
3351  }
3352  }
3353 
3354  memcpy(&mediaStatus.m_mediaTrackInfo, &lstAVMediaPlayer->m_mediaTrackInfo, sizeof(stBTRCoreAVMediaTrackInfo));
3355  BTRCORELOG_DEBUG ("AV Media Player Track Updated : %s", mediaStatus.m_mediaTrackInfo.pcTitle);
3356  postEvent = TRUE;
3357  break;
3358 
3359  case enBTMedPlayerPropEqualizer:
3360  switch (apstBtMediaStUpdate->enMediaPlayerEqualizer) {
3361  case enBTMedPlayerEqualizerOff:
3362  lstAVMediaPlayer->eAVMediaPlayerEqualizer = eBTRCoreAVMediaPlyrEqlzrStOff;
3363  break;
3364  case enBTMedPlayerEqualizerOn:
3365  lstAVMediaPlayer->eAVMediaPlayerEqualizer = eBTRCoreAVMediaPlyrEqlzrStOn;
3366  break;
3367  default:
3368  lstAVMediaPlayer->eAVMediaPlayerEqualizer = enBTRCoreAVMediaCtrlUnknown;
3369  }
3370  mediaStatus.eAVMediaState = lstAVMediaPlayer->eAVMediaPlayerEqualizer;
3371  BTRCORELOG_DEBUG ("AV Media Player Equalizer : %d\n", lstAVMediaPlayer->eAVMediaPlayerEqualizer);
3372  postEvent = TRUE;
3373  break;
3374 
3375  case enBTMedPlayerPropShuffle:
3376  switch (apstBtMediaStUpdate->enMediaPlayerShuffle) {
3377  case enBTMedPlayerShuffleOff:
3378  lstAVMediaPlayer->eAVMediaPlayerShuffle = eBTRCoreAVMediaPlyrShflStOff;
3379  break;
3380  case enBTMedPlayerShuffleAllTracks:
3381  lstAVMediaPlayer->eAVMediaPlayerShuffle = eBTRCoreAVMediaPlyrShflStAllTracks;
3382  break;
3383  case enBTMedPlayerShuffleGroup:
3384  lstAVMediaPlayer->eAVMediaPlayerShuffle = eBTRCoreAVMediaPlyrShflStGroup;
3385  break;
3386  default:
3387  lstAVMediaPlayer->eAVMediaPlayerShuffle = eBTRCoreAVMediaStUnknown;
3388  }
3389  mediaStatus.eAVMediaState = lstAVMediaPlayer->eAVMediaPlayerShuffle;
3390  BTRCORELOG_DEBUG ("AV Media Player Shuffle : %d\n", lstAVMediaPlayer->eAVMediaPlayerShuffle);
3391  postEvent = TRUE;
3392  break;
3393 
3394  case enBTMedPlayerPropRepeat:
3395  switch (apstBtMediaStUpdate->enMediaPlayerRepeat) {
3396  case enBTMedPlayerRpOff:
3397  lstAVMediaPlayer->eAVMediaPlayerRepeat = eBTRCoreAVMediaPlyrRptStOff;
3398  break;
3399  case enBTMedPlayerRpSingleTrack:
3400  lstAVMediaPlayer->eAVMediaPlayerRepeat = eBTRCoreAVMediaPlyrRptStSingleTrack;
3401  break;
3402  case enBTMedPlayerRpAllTracks:
3403  lstAVMediaPlayer->eAVMediaPlayerRepeat = eBTRCoreAVMediaPlyrRptStAllTracks;
3404  break;
3405  case enBTMedPlayerRpGroup:
3406  lstAVMediaPlayer->eAVMediaPlayerRepeat = eBTRCoreAVMediaPlyrRptStGroup;
3407  break;
3408  default:
3409  lstAVMediaPlayer->eAVMediaPlayerRepeat = eBTRCoreAVMediaStUnknown;
3410  }
3411  mediaStatus.eAVMediaState = lstAVMediaPlayer->eAVMediaPlayerRepeat;
3412  BTRCORELOG_DEBUG ("AV Media Player Repeat : %d\n", lstAVMediaPlayer->eAVMediaPlayerRepeat);
3413  postEvent = TRUE;
3414  break;
3415 
3416  case enBTMedPlayerPropScan:
3417  switch (apstBtMediaStUpdate->enMediaPlayerScan) {
3418  case enBTMedPlayerScanOff:
3419  lstAVMediaPlayer->eAVMediaPlayerScan = eBTRCoreAVMediaPlyrScanStOff;
3420  break;
3421  case enBTMedPlayerScanAllTracks:
3422  lstAVMediaPlayer->eAVMediaPlayerScan = eBTRCoreAVMediaPlyrScanStAllTracks;
3423  break;
3424  case enBTMedPlayerScanGroup:
3425  lstAVMediaPlayer->eAVMediaPlayerScan = eBTRCoreAVMediaPlyrScanStGroup;
3426  break;
3427  default:
3428  lstAVMediaPlayer->eAVMediaPlayerScan = eBTRCoreAVMediaStUnknown;
3429  }
3430  BTRCORELOG_DEBUG ("AV Media Player Scan : %d\n", lstAVMediaPlayer->eAVMediaPlayerScan);
3431  break;
3432 
3433  case enBTMedPlayerPropPosition:
3434  lstAVMediaPlayer->m_mediaPlayerPosition = apstBtMediaStUpdate->m_mediaPlayerPosition;
3435  BTRCORELOG_DEBUG ("AV Media Player Position : %d\n", lstAVMediaPlayer->m_mediaPlayerPosition);
3436  break;
3437 
3438  case enBTMedPlayerPropStatus:
3439  switch (apstBtMediaStUpdate->enMediaPlayerStatus) {
3440  case enBTMedPlayerStPlaying:
3441  lstAVMediaPlayer->eAVMediaStatusUpdate = eBTRCoreAVMediaTrkStPlaying;
3442  break;
3443  case enBTMedPlayerStStopped:
3444  lstAVMediaPlayer->eAVMediaStatusUpdate = eBTRCoreAVMediaTrkStStopped;
3445  break;
3446  case enBTMedPlayerStPaused:
3447  lstAVMediaPlayer->eAVMediaStatusUpdate = eBTRCoreAVMediaTrkStPaused;
3448  break;
3449  case enBTMedPlayerStForwardSeek:
3450  lstAVMediaPlayer->eAVMediaStatusUpdate = eBTRCoreAVMediaTrkStForwardSeek;
3451  break;
3452  case enBTMedPlayerStReverseSeek:
3453  lstAVMediaPlayer->eAVMediaStatusUpdate = eBTRCoreAVMediaTrkStReverseSeek;
3454  break;
3455  case enBTMedPlayerStError:
3456  lstAVMediaPlayer->eAVMediaStatusUpdate = eBTRCoreAVMediaPlaybackError;
3457  break;
3458  default:
3459  lstAVMediaPlayer->eAVMediaStatusUpdate = eBTRCoreAVMediaPlaybackError;
3460  }
3461  BTRCORELOG_DEBUG ("AV Media Player Status : %d\n", lstAVMediaPlayer->eAVMediaStatusUpdate);
3462  break;
3463 
3464  case enBTMedPlayerPropBrowsable:
3465  lstAVMediaPlayer->m_mediaPlayerBrowsable = apstBtMediaStUpdate->m_mediaPlayerBrowsable;
3466  BTRCORELOG_DEBUG ("AV Media Player Browsable : %d\n", lstAVMediaPlayer->m_mediaPlayerBrowsable);
3467  postEvent = TRUE;
3468  break;
3469 
3470  case enBTMedPlayerPropSearchable:
3471  lstAVMediaPlayer->m_mediaPlayerSearchable = apstBtMediaStUpdate->m_mediaPlayerSearchable;
3472  BTRCORELOG_DEBUG ("AV Media Player Searchable : %d\n", lstAVMediaPlayer->m_mediaPlayerSearchable);
3473  postEvent = TRUE;
3474  break;
3475 
3476  case enBTMedPlayerPropPlaylist:
3477  mediaStatus.eAVMediaState = eBTRCoreAVMediaElementAdded;
3478 
3479  if (pstlhBTRCoreAVM->pstAVMediaPlayList) {
3480  strncpy (mediaStatus.m_mediaElementInfo.m_mediaElementName, pstlhBTRCoreAVM->pstAVMediaPlayList->pcAVMediaItemName, BTRCORE_MAX_STR_LEN -1);
3481  mediaStatus.m_mediaElementInfo.ui32AVMediaElementId = pstlhBTRCoreAVM->pstAVMediaPlayList->ui32AVMediaItemId;
3482  mediaStatus.m_mediaElementInfo.bIsPlayable = 0;
3483  BTRCORELOG_DEBUG ("AV Media Player PlayList %p:%s [ID: %llu]\n", pstlhBTRCoreAVM->pstAVMediaPlayList
3484  , pstlhBTRCoreAVM->pstAVMediaPlayList->pcAVMediaItemName
3485  , pstlhBTRCoreAVM->pstAVMediaPlayList->ui32AVMediaItemId);
3486  //postEvent = TRUE;
3487  /* Do post PlayList Addition works here */
3488  }
3489  else {
3490  BTRCORELOG_WARN ("AV Media Player PlayList %p Exist\n", pstlhBTRCoreAVM->pstAVMediaPlayList);
3491  }
3492  break;
3493  default:
3494  break;
3495  }
3496  }
3497  break;
3498 
3499  case enBTMediaItem:
3500  /*
3501  switch(apstBtMediaStUpdate->aunBtOpIfceProp.enBtMediaItemProp) {
3502  case Playable
3503  case Metadata
3504  }
3505  */
3506  break;
3507  case enBTMediaFolder:
3508  switch(apstBtMediaStUpdate->aunBtOpIfceProp.enBtMediaFolderProp) {
3509  case enBTMedFolderPropName:
3510  {
3511  unsigned char bChanged = 0;
3512  stBTRCoreAVMediaItem* ptr = NULL;
3513  stBTRCoreAVMediaPlayer* ptrPlayer = &pstlhBTRCoreAVM->pstAVMediaPlayer;
3514  BTRCORELOG_DEBUG ("AV Media Folder Name : %s\n", apstBtMediaStUpdate->m_mediaFolderName);
3515 
3516  if (strcmp(apstBtMediaStUpdate->m_mediaFolderName, "NowPlaying") && (ptr = pstlhBTRCoreAVM->pstAVMediaBrowser)) {
3517  unsigned int ui32Index = 0;
3518  char* staStr = apstBtMediaStUpdate->m_mediaFolderName;
3519 
3520  if (ptr->pvAVMediaParentItem) {
3521  char* bsrStr = ((stBTRCoreAVMediaItem*)ptr->pvAVMediaParentItem)->pcAVMediaItemName;
3522 
3523  if (!strncmp(staStr, bsrStr, (strlen(staStr) > strlen(bsrStr))? strlen(staStr) : strlen(bsrStr))) {
3524  ptrPlayer->m_mediaBrowserItem = pstlhBTRCoreAVM->pstAVMediaBrowser = ptr->pvAVMediaParentItem;
3525  bChanged = 1;
3526  }
3527  }
3528 
3529  ptr = pstlhBTRCoreAVM->pstAVMediaBrowser;
3530 
3531  while (!bChanged && ui32Index < ptr->ui32AVMediaNumberOfItems) {
3532  char* bsrStr = ptr->pstAVMediaSubItems[ui32Index]->pcAVMediaItemName;
3533 
3534  if (!strncmp(staStr, bsrStr, (strlen(staStr) > strlen(bsrStr))? strlen(staStr) : strlen(bsrStr))) {
3535  ptrPlayer->m_mediaBrowserItem = pstlhBTRCoreAVM->pstAVMediaBrowser = ptr->pstAVMediaSubItems[ui32Index];
3536  bChanged = 1;
3537  }
3538  ui32Index++;
3539  }
3540  }
3541  else if (!strcmp(apstBtMediaStUpdate->m_mediaFolderName, "NowPlaying") && pstlhBTRCoreAVM->pstAVMediaPlayList) {
3542  ptrPlayer->m_mediaBrowserItem = pstlhBTRCoreAVM->pstAVMediaPlayList;
3543  bChanged = 1;
3544  }
3545  else {
3546  BTRCORELOG_ERROR ("No Filesystem is present for %s !\n", apstBtMediaStUpdate->m_mediaFolderName);
3547  }
3548 
3549  if (bChanged) {
3550  BTRCORELOG_DEBUG ("Browsing Location %p:%s [ID: %llu]\n", ptrPlayer->m_mediaBrowserItem
3551  , ptrPlayer->m_mediaBrowserItem->pcAVMediaItemName
3552  , ptrPlayer->m_mediaBrowserItem->ui32AVMediaItemId);
3553  }
3554  break;
3555  }
3556  case enBTMedFolderPropNumberOfItems:
3557  BTRCORELOG_DEBUG ("AV Media Folder NumberOfItems : %u\n", apstBtMediaStUpdate->m_mediaFolderNumberOfItems);
3558  break;
3559  default:
3560  break;
3561  }
3562  break;
3563  default:
3564  break;
3565  }
3566 
3567  if (!pstlhBTRCoreAVM->pcBMediaStatusUserData) {
3568  BTRCORELOG_ERROR ("pstlhBTRCoreAVM->pcBMediaStatusUserData is NULL!!!\n");
3569  postEvent = FALSE;
3570  i32BtRet = -1;
3571  }
3572 
3573  /* post callback */
3574  if (postEvent && pstlhBTRCoreAVM->fpcBBTRCoreAVMediaStatusUpdate) {
3575 
3576  if (aeBtDeviceType == enBTDevAudioSink) {
3577  mediaStatus.eAVMediaDataFlow = eBTRCoreAVMediaFlowOut;
3578  }
3579  else if (aeBtDeviceType == enBTDevAudioSource) {
3580  mediaStatus.eAVMediaDataFlow = eBTRCoreAVMediaFlowIn;
3581  }
3582  else if ((aeBtDeviceType == enBTDevHFPHeadset) || (aeBtDeviceType == enBTDevHFPAudioGateway)) {
3583  mediaStatus.eAVMediaDataFlow = eBTRCoreAVMediaFlowInOut;
3584  }
3585  else {
3586  mediaStatus.eAVMediaDataFlow = eBTRCoreAVMediaFlowUnknown;
3587  }
3588 
3589  if (pstlhBTRCoreAVM->fpcBBTRCoreAVMediaStatusUpdate(&mediaStatus, apcBtDevAddr, pstlhBTRCoreAVM->pcBMediaStatusUserData) != enBTRCoreSuccess) {
3590  BTRCORELOG_ERROR ("fpcBBTRCoreAVMediaStatusUpdate - Failure !!!\n");
3591  i32BtRet = -1;
3592  }
3593  }
3594 
3595  return i32BtRet;
3596 }
3597 
3598 static int
3599 btrCore_AVMedia_MediaBrowserUpdateCb (
3600  stBTMediaBrowserUpdate* apstBtMediaBsrUpdate,
3601  unsigned char ucItemScope,
3602  const char* apcBtDevAddr,
3603  void* apUserData
3604 ) {
3605  stBTRCoreAVMediaHdl* pstlhBTRCoreAVM = NULL;
3606  stBTRCoreAVMediaItem* ptr = NULL;
3607  stBTRCoreAVMediaItem** ptrRoot = NULL;
3608  int i32BtRet = -1;
3609  BOOLEAN postEvent = FALSE;
3610 
3611  stBTRCoreAVMediaStatusUpdate mediaStatus;
3612  stBTRCoreAVMediaElementInfo* mediaElement;
3613 
3614  if (!apstBtMediaBsrUpdate || !apUserData) {
3615  BTRCORELOG_ERROR ("enBTRCoreInvalidArg!!!\n");
3616  return i32BtRet;
3617  }
3618  BTRCORELOG_DEBUG ("AV Media Browser Cb\n");
3619 
3620  pstlhBTRCoreAVM = (stBTRCoreAVMediaHdl*)apUserData;
3621 
3622  if (!pstlhBTRCoreAVM->pstAVMediaPlayer.m_mediaPlayerBrowsable &&
3623  apstBtMediaBsrUpdate->ui32BTMediaItemId != BTR_MEDIA_PLAYLIST_ID &&
3624  apstBtMediaBsrUpdate->ui32BTMediaItemId) {
3625  return 0;
3626  }
3627 
3628  mediaElement = &mediaStatus.m_mediaElementInfo;
3629  ptr = *(ptrRoot = (apstBtMediaBsrUpdate->ui32BTMediaItemId & BTR_MEDIA_PLAYLIST_ID)? &pstlhBTRCoreAVM->pstAVMediaPlayList : &pstlhBTRCoreAVM->pstAVMediaBrowser);
3630 
3631  if (ucItemScope) {
3632 
3633  stBTRCoreAVMediaItem* lpstBroswer = NULL;
3634 
3635  if (apstBtMediaBsrUpdate->eMediaItemType == enBTMediaItemTypFolder ||
3636  apstBtMediaBsrUpdate->eMediaItemType == enBTMediaItemTypAudio) {
3637 
3638  if (!(i32BtRet = btrCore_AVMedia_AllocateBrowserMemory (pstlhBTRCoreAVM, ptr, &lpstBroswer))) {
3639 
3640  lpstBroswer->pvAVMediaParentItem = ptr;
3641  lpstBroswer->ui32AVMediaNumberOfItems = 0;
3642  lpstBroswer->eMediaItemType = btrCore_AVMedia_MapFolderTypeToElementType (apstBtMediaBsrUpdate->eMediaFolderType);
3643  lpstBroswer->ui32AVMediaItemId = apstBtMediaBsrUpdate->ui32BTMediaItemId;
3644  strncpy(lpstBroswer->pcAVMediaItemPath, apstBtMediaBsrUpdate->pcMediaItemPath, BTRCORE_MAX_STR_LEN -1);
3645  strncpy(lpstBroswer->pcAVMediaItemName, apstBtMediaBsrUpdate->pcMediaItemName, BTRCORE_MAX_STR_LEN -1);
3646 
3647  if ((lpstBroswer->bIsMediaItemPlayable = (apstBtMediaBsrUpdate->eMediaItemType == enBTMediaItemTypAudio))) {
3648  memcpy (&lpstBroswer->mediaTrackInfo, &apstBtMediaBsrUpdate->mediaTrackInfo, sizeof(stBTRCoreAVMediaTrackInfo)),
3649  (lpstBroswer->ui32AVMediaItemId & BTR_MEDIA_PLAYLIST_ID)? pstlhBTRCoreAVM->ui32AVMediaPlayListItemCount++ : pstlhBTRCoreAVM->ui32AVMediaBrowserItemCount++;
3650  }
3651  else {
3652  if (!ptr) {
3653  if (!(*ptrRoot = lpstBroswer)->ui32AVMediaItemId) {
3654  pstlhBTRCoreAVM->pstAVMediaPlayer.m_mediaBrowserItem = lpstBroswer;
3655  }
3656  }
3657  }
3658 
3659  if (postEvent) {
3660  mediaStatus.eAVMediaState = eBTRCoreAVMediaElementAdded;
3661  mediaElement->eAVMElementType = btrCore_AVMedia_MapFolderTypeToElementType (apstBtMediaBsrUpdate->eMediaFolderType);
3662  mediaElement->ui32AVMediaElementId = lpstBroswer->ui32AVMediaItemId = apstBtMediaBsrUpdate->ui32BTMediaItemId;
3663  if ((mediaElement->bIsPlayable = lpstBroswer->bIsMediaItemPlayable)) {
3664  memcpy (&mediaElement->m_mediaTrackInfo, &lpstBroswer->mediaTrackInfo, sizeof(stBTRCoreAVMediaTrackInfo));
3665  }
3666  strncpy(mediaElement->m_mediaElementName, lpstBroswer->pcAVMediaItemName, BTRCORE_MAX_STR_LEN -1);
3667  }
3668  BTRCORELOG_DEBUG ("Storing Media Item %p:%s [ID: %llu]\n", lpstBroswer, lpstBroswer->pcAVMediaItemName, lpstBroswer->ui32AVMediaItemId);
3669  }
3670  else {
3671  BTRCORELOG_ERROR ("Media Browser Error - Allocate Browser Memory Failed!\n");
3672  }
3673  }
3674  else if (apstBtMediaBsrUpdate->eMediaItemType == enBTMediaItemTypVideo) {
3675  BTRCORELOG_DEBUG ("enBTMediaItemTypVideo received\n");
3676  i32BtRet = 0;
3677  }
3678  else {
3679  BTRCORELOG_ERROR ("Unknown MediaItem type received : %d !\n", apstBtMediaBsrUpdate->eMediaItemType);
3680  }
3681  }
3682  else { /* To implement subFolder/AudioTrack search based on unique mediaItemID for better performance */
3683  stBTRCoreAVMediaItem* pstMediaItemRoot = 0;
3684 
3685  if (!(pstMediaItemRoot = ptr)) {
3686  BTRCORELOG_ERROR ("Media Browser Error - No parent Filesystem !\n");
3687  return i32BtRet;
3688  }
3689 
3690  while (pstMediaItemRoot->pvAVMediaParentItem) {
3691  pstMediaItemRoot = pstMediaItemRoot->pvAVMediaParentItem;
3692  }
3693 
3694  if (btrCore_AVMedia_FindMediaItem (pstMediaItemRoot, apstBtMediaBsrUpdate->ui32BTMediaItemId, &ptr)) {
3695  BTRCORELOG_ERROR ("Media Browser Error - Couldn't Find MediaItem %llu\n", apstBtMediaBsrUpdate->ui32BTMediaItemId);
3696  }
3697  else
3698  if (ptr) { /* ptr will be updated if the above Find menthod is successfull */
3699 
3700  if (ptr->ui32AVMediaNumberOfItems || (ptr->pstAVMediaSubItems && !ptr->bIsMediaItemPlayable)) {
3701  BTRCORELOG_WARN ("!!!Media Browser Error - contains MediaSubItems\n");
3702  BTRCORELOG_WARN ("!!!No.OfItems : %u | SubItems : %p\n", ptr->ui32AVMediaNumberOfItems, ptr->pstAVMediaSubItems);
3703  mediaElement->ui32AVMediaElementId = (*ptrRoot)->ui32AVMediaItemId;
3704 
3705  if (!(i32BtRet = btrCore_AVMedia_DeallocateUnhandledBrowserMemory (pstlhBTRCoreAVM, apcBtDevAddr, &ptr))) {
3706  if (mediaElement->ui32AVMediaElementId == apstBtMediaBsrUpdate->ui32BTMediaItemId) {
3707  *ptrRoot = ptr;
3708  }
3709  }
3710  else {
3711  BTRCORELOG_ERROR ("Media Browser Error - Deallocate Unhandled Browser Memory Failed!\n");
3712  }
3713  postEvent = FALSE;
3714  }
3715  else {
3716  BTRCORELOG_DEBUG ("Freeing Media Item %p:%s [ID: %llu]\n", ptr, ptr->pcAVMediaItemName, ptr->ui32AVMediaItemId);
3717  mediaElement->ui32AVMediaElementId = (*ptrRoot)->ui32AVMediaItemId;
3718 
3719  if (ptr->bIsMediaItemPlayable) {
3720  (apstBtMediaBsrUpdate->ui32BTMediaItemId & BTR_MEDIA_PLAYLIST_ID)? pstlhBTRCoreAVM->ui32AVMediaPlayListItemCount-- : pstlhBTRCoreAVM->ui32AVMediaBrowserItemCount--;
3721  }
3722 
3723  if (!(i32BtRet = btrCore_AVMedia_DeallocateBrowserMemory(pstlhBTRCoreAVM, &ptr))) {
3724  if (mediaElement->ui32AVMediaElementId == apstBtMediaBsrUpdate->ui32BTMediaItemId) {
3725  *ptrRoot = ptr; /* Moving to root will be good for the next connection - Inform through Event? */
3726  }
3727 
3728  mediaStatus.eAVMediaState = eBTRCoreAVMediaElementRemoved;
3729  mediaElement->ui32AVMediaElementId = apstBtMediaBsrUpdate->ui32BTMediaItemId;
3730  }
3731  else {
3732  BTRCORELOG_ERROR ("Media Browser Error - Deallocate Browser Memory Failed!\n");
3733  }
3734  }
3735  }
3736  }
3737 
3738  /* post callback */
3739  if (postEvent && !i32BtRet && pstlhBTRCoreAVM->fpcBBTRCoreAVMediaStatusUpdate) {
3740  if (pstlhBTRCoreAVM->fpcBBTRCoreAVMediaStatusUpdate(&mediaStatus, apcBtDevAddr, pstlhBTRCoreAVM->pcBMediaStatusUserData) != enBTRCoreSuccess) {
3741  BTRCORELOG_ERROR ("fpcBBTRCoreAVMediaStatusUpdate - Failure !!!\n");
3742  i32BtRet = -1;
3743  }
3744  }
3745 
3746  return i32BtRet;
3747 }
_stBTMediaStatusUpdate
Definition: btrCore_bt_ifce.h:700
BOOLEAN
unsigned char BOOLEAN
DTCP Manager return codes.
Definition: dtcpmgr.h:163
BT_UUID_A2DP_SOURCE
#define BT_UUID_A2DP_SOURCE
Bluetooth A2DP Source UUID.
Definition: btrCore_bt_ifce.h:80
BtrCore_BTDevMediaControl
int BtrCore_BTDevMediaControl(void *apBtConn, const char *apmediaPlayerPath, enBTMediaControlCmd aenBTMediaOper)
This API is used to control the media device.
Definition: btrCore_dbus_bluez5.c:6089
_stBTMediaTrackInfo
Definition: btrCore_bt_ifce.h:689
BTRCore_AVMedia_IsMediaElementPlayable
enBTRCoreRet BTRCore_AVMedia_IsMediaElementPlayable(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, tBTRCoreAVMediaElementId aBtrAVMediaItemId, char *isPlayable)
This API is used to find if a MediaElement is Playable or Non-Playable.
Definition: btrCore_avMedia.c:2330
BtrCore_BTPlayMediaTrackItem
int BtrCore_BTPlayMediaTrackItem(void *apstBtIfceHdl, const char *apBtMediaItemObjectPath)
This API is used to Play the mentioned media track.
Definition: btrCore_dbus_bluez5.c:6632
BtrCore_BTRegisterMedia
int BtrCore_BTRegisterMedia(void *apBtConn, const char *apBtAdapter, enBTDeviceType aenBTDevType, enBTMediaType aenBTMediaType, const char *apBtUUID, void *apBtMediaCapabilities, int apBtMediaCapabilitiesSize, int abBtMediaDelayReportEnable)
This API is used to register a media device.
Definition: btrCore_dbus_bluez5.c:5594
enBTMediaType
enum _enBTMediaType enBTMediaType
Bluetooth Media types.
_stBTMediaBrowserUpdate
Definition: btrCore_bt_ifce.h:726
_stBTRCoreAVMediaItemFilter
Definition: btrCore_avMedia.c:231
BtrCore_BTSetProp
int BtrCore_BTSetProp(void *apBtConn, const char *apcOpIfcePath, enBTOpIfceType aenBtOpIfceType, unBTOpIfceProp aunBtOpIfceProp, void *apvVal)
This API sets different properties of different BT devices and services.
Definition: btrCore_dbus_bluez4.c:1737
_stBTRCoreAVMediaElementInfoList
Definition: btrCore_avMedia.h:195
BTRCore_AVMedia_GetMediaElementList
enBTRCoreRet BTRCore_AVMedia_GetMediaElementList(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, tBTRCoreAVMediaElementId aBtrAVMediaElementId, unsigned short aui16StartIdx, unsigned short aui16EndIdx, eBTRCoreAVMElementType aeBtrAVMElementType, stBTRCoreAVMediaElementInfoList *aAVMediaElementInfoList)
This API is used to fetch the media item list.
Definition: btrCore_avMedia.c:2121
enBTDeviceType
enum _enBTDeviceType enBTDeviceType
Bluetooth device types.
BTRCore_AVMedia_GetElementTrackInfo
enBTRCoreRet BTRCore_AVMedia_GetElementTrackInfo(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, tBTRCoreAVMediaElementId aBtrAVMediaItemId, stBTRCoreAVMediaTrackInfo *apstBTAVMediaTrackInfo)
This API is used to retrieve the information about the track that is being played on the media device...
Definition: btrCore_avMedia.c:1797
BtrCore_BTGetCommonParentMediaItemId
tBTMediaItemId BtrCore_BTGetCommonParentMediaItemId(tBTMediaItemId aBTcurrMediaItemId, tBTMediaItemId aBTdestMediaItemId)
This API is used to get the mediaItemID of the node which is the immediate common parent of the src a...
Definition: btrCore_dbus_bluez5.c:6419
BTRCore_AVMedia_GetTrackInfo
enBTRCoreRet BTRCore_AVMedia_GetTrackInfo(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, stBTRCoreAVMediaTrackInfo *apstBTAVMediaTrackInfo)
This API is used to retrieve the information about the track that is being played on the media device...
Definition: btrCore_avMedia.c:1763
_unBTOpIfceProp
Definition: btrCore_bt_ifce.h:609
BtrCore_BTReleaseDevDataPath
int BtrCore_BTReleaseDevDataPath(void *apBtConn, char *apcDevTransportPath)
This API is used to release the acquired device data path.
Definition: btrCore_dbus_bluez4.c:2859
BtrCore_BTGetMediaFolderNumberOfItems
int BtrCore_BTGetMediaFolderNumberOfItems(void *apBtConn, const char *apBtMediaPlayerPath, unsigned int *aui32NumberOfItems)
This API is used to get the number of items in the current media folder.
Definition: btrCore_dbus_bluez5.c:6267
BTRCore_AVMedia_ChangeBrowserLocation
enBTRCoreRet BTRCore_AVMedia_ChangeBrowserLocation(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, tBTRCoreAVMediaElementId aBtrAVMediaElementId, eBTRCoreAVMElementType aeBtrAVMElementType)
This API is used to change the media browsing location in the connected AudioIn device.
Definition: btrCore_avMedia.c:1931
enBTMediaControlCmd
enum _enBTMediaControlCmd enBTMediaControlCmd
Bluetooth Media Controls.
BTRCore_AVMedia_DeInit
enBTRCoreRet BTRCore_AVMedia_DeInit(tBTRCoreAVMediaHdl hBTRCoreAVM, void *apBtConn, const char *apBtAdapter)
This API DeInitializes the media device by unregistering both source and sink.
Definition: btrCore_avMedia.c:1097
BTRCore_AVMedia_Init
enBTRCoreRet BTRCore_AVMedia_Init(tBTRCoreAVMediaHdl *phBTRCoreAVM, void *apBtConn, const char *apBtAdapter)
This API Initializes the media device by registering both source and sink.
Definition: btrCore_avMedia.c:912
BTRCore_AVMedia_GetPositionInfo
enBTRCoreRet BTRCore_AVMedia_GetPositionInfo(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, stBTRCoreAVMediaPositionInfo *apstBTAVMediaPositionInfo)
This API is used to retrieve the position information about the media device.
Definition: btrCore_avMedia.c:1846
BtrCore_BTAcquireDevDataPath
int BtrCore_BTAcquireDevDataPath(void *apBtConn, char *apcDevTransportPath, int *dataPathFd, int *dataReadMTU, int *dataWriteMTU)
This API is used to acquire device data path.
Definition: btrCore_dbus_bluez4.c:2793
_stBTRCoreAVMediaCtData
Definition: btrCore_avMedia.h:215
_stBTRCoreAVMediaHdl
Definition: btrCore_avMedia.c:270
BTRCore_AVMedia_GetCurMediaInfo
enBTRCoreRet BTRCore_AVMedia_GetCurMediaInfo(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, stBTRCoreAVMediaInfo *apstBtrCoreAVMediaInfo)
This API gets current media information of the media device by unregistering both source and sink.
Definition: btrCore_avMedia.c:1214
BT_UUID_A2DP_SINK
#define BT_UUID_A2DP_SINK
Bluetooth A2DP Sink UUID.
Definition: btrCore_bt_ifce.h:85
_stBTRCoreAVMediaPlayer
Definition: btrCore_avMedia.c:252
_stBTRCoreAVMediaPositionInfo
Definition: btrCore_avMedia.h:182
BtrCore_BTGetProp
int BtrCore_BTGetProp(void *apBtConn, const char *apcOpIfcePath, enBTOpIfceType aenBtOpIfceType, unBTOpIfceProp aunBtOpIfceProp, void *apvVal)
This API gets different properties of different BT devices and services.
Definition: btrCore_dbus_bluez4.c:1560
BtrCore_BTUnRegisterMedia
int BtrCore_BTUnRegisterMedia(void *apBtConn, const char *apBtAdapter, enBTDeviceType aenBTDevType, enBTMediaType aenBTMediaType)
This API is used to unregister the media device.
Definition: btrCore_dbus_bluez5.c:5789
BtrCore_BTGetMediaPlayerProperty
int BtrCore_BTGetMediaPlayerProperty(void *apBtConn, const char *apBtObjectPath, const char *mediaProperty, void *mediaPropertyValue)
This API is used to get media player property value using the object path of BT device and media prop...
Definition: btrCore_dbus_bluez4.c:3112
BTRCore_AVMedia_ReleaseDataPath
enBTRCoreRet BTRCore_AVMedia_ReleaseDataPath(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr)
This API releases the acquired data path of the media device.
Definition: btrCore_avMedia.c:1592
BtrCore_BTChangeMediaFolder
int BtrCore_BTChangeMediaFolder(void *apstBtIfceHdl, const char *apBtmediaPlayerObjectPath, const char *apBtdestMediaFolderPath)
This API is used to change from the current media folder path to another path.
Definition: btrCore_dbus_bluez5.c:6441
BTRCore_AVMedia_PlayTrack
enBTRCoreRet BTRCore_AVMedia_PlayTrack(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, tBTRCoreAVMediaElementId aBtrAVMediaItemId)
This API starts playing the mentioned media item.
Definition: btrCore_avMedia.c:2212
_stBTRCoreAVMediaMpegInfo
Definition: btrCore_avMedia.h:152
_stBTRCoreAVMediaSbcInfo
Definition: btrCore_avMedia.h:139
BtrCore_BTGetTrackInformation
int BtrCore_BTGetTrackInformation(void *apBtConn, const char *apBtmediaPlayerObjectPath, stBTMediaTrackInfo *lpstBTMediaTrackInfo)
This API is used to retrieve the information about the track that is being played on BT media device.
Definition: btrCore_dbus_bluez5.c:6352
_stBTRCoreAVMediaInfo
Definition: btrCore_avMedia.h:166
_stBTRCoreAVMediaStatusUserData
Definition: btrCore_avMedia.c:308
_stBTRCoreAVMediaElementInfo
Definition: btrCore_avMedia.h:187
_stBTRCoreAVMediaTrackInfo
Definition: btrCore_avMedia.h:172
_stBTRCoreAVMediaStatusUpdate
Definition: btrCore_avMedia.h:200
BTRCore_AVMedia_GetMediaProperty
enBTRCoreRet BTRCore_AVMedia_GetMediaProperty(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, const char *mediaPropertyKey, void *mediaPropertyValue)
This API is used to get media property value using the device address and media property key.
Definition: btrCore_avMedia.c:1895
BTRCore_AVMedia_SelectTrack
enBTRCoreRet BTRCore_AVMedia_SelectTrack(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, tBTRCoreAVMediaElementId aBtrAVMediaItemId)
This API select track the mentioned media item.
Definition: btrCore_avMedia.c:2267
BTRCore_AVMedia_SelectMediaBrowserElements
enBTRCoreRet BTRCore_AVMedia_SelectMediaBrowserElements(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, unsigned short aui16StartIdx, unsigned short aui16EndIdx)
This API is used to List(implicitly) the media elements in the current browsing location of the conne...
Definition: btrCore_avMedia.c:2052
_stBTRCoreAVMediaItem
Definition: btrCore_avMedia.c:237
BtrCore_BTGetMediaPlayerPath
char * BtrCore_BTGetMediaPlayerPath(void *apBtConn, const char *apBtDevPath)
A Path is assigned to Media player using Bluetooth device path.
Definition: btrCore_dbus_bluez5.c:6053
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199
BtrCore_BTSelectMediaFolderItems
int BtrCore_BTSelectMediaFolderItems(void *apstBtIfceHdl, const char *apBtMediaPlayerObjectPath, unsigned int apBtMediaFolderStartIndex, unsigned int apBtMediaFolderEndIndex, const char *apBtMediaFilter, int apBtMediaFilterSize)
This API is used to list the media items in the current folder.
Definition: btrCore_dbus_bluez5.c:6485
BTRCore_AVMedia_MediaControl
enBTRCoreRet BTRCore_AVMedia_MediaControl(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, enBTRCoreAVMediaCtrl aenBTRCoreAVMediaCtrl, eBTRCoreAVMediaFlow aenBTRCoreAVMediaFlow, stBTRCoreAVMediaCtData *apstBTRCoreAVMediaCtrlData)
This API is used to control the media device. BTRCore_MediaControl() invokes this API.
Definition: btrCore_avMedia.c:1629
BTRCore_AVMedia_RegisterMediaStatusUpdateCb
enBTRCoreRet BTRCore_AVMedia_RegisterMediaStatusUpdateCb(tBTRCoreAVMediaHdl hBTRCoreAVM, fPtr_BTRCore_AVMediaStatusUpdateCb afpcBBTRCoreAVMediaStatusUpdate, void *apvBMediaStatusUserData)
Definition: btrCore_avMedia.c:2388
BTRCore_AVMedia_AcquireDataPath
enBTRCoreRet BTRCore_AVMedia_AcquireDataPath(tBTRCoreAVMediaHdl hBTRCoreAVM, const char *apBtDevAddr, int *apDataPath, int *apDataReadMTU, int *apDataWriteMTU, unsigned int *apui32Delay)
This API acquires the data path and MTU of a media device.
Definition: btrCore_avMedia.c:1538