NPT_Result GPAC_MediaController::Browse(GPAC_MediaServerItem *server, const char *object_id, const char *filter) { NPT_Result res = NPT_FAILURE; NPT_Int32 index = 0; // reset output params server->m_BrowseResults = NULL; do { PLT_BrowseDataReference browse_data(new PLT_BrowseData()); // send off the browse packet. Note that this will // not block. There is a call to WaitForResponse in order // to block until the response comes back. res = Browse(browse_data, server->m_device, (const char*)object_id, index, 1024, false, filter, ""); NPT_CHECK_LABEL_WARNING(res, done); if (NPT_FAILED(browse_data->res)) { res = browse_data->res; NPT_CHECK_LABEL_WARNING(res, done); } if (browse_data->info.items->GetItemCount() == 0) break; if (server->m_BrowseResults.IsNull()) { server->m_BrowseResults = browse_data->info.items; } else { server->m_BrowseResults->Add(*browse_data->info.items); // clear the list items so that the data inside is not // cleaned up by PLT_MediaItemList dtor since we copied // each pointer into the new list. browse_data->info.items->Clear(); } // stop now if our list contains exactly what the server said it had if (browse_data->info.tm && browse_data->info.tm == server->m_BrowseResults->GetItemCount()) break; // ask for the next chunk of entries index = server->m_BrowseResults->GetItemCount(); } while(1); done: return res; }
/*---------------------------------------------------------------------- | PLT_SyncMediaBrowser::BrowseSync +---------------------------------------------------------------------*/ NPT_Result PLT_SyncMediaBrowser::BrowseSync(PLT_DeviceDataReference& device, const char* object_id, PLT_MediaObjectListReference& list, bool metadata, /* = false */ NPT_Int32 start, /* = 0 */ NPT_Cardinal max_results /* = 0 */) { NPT_Result res = NPT_FAILURE; NPT_Int32 index = start; // reset output params list = NULL; // look into cache first if (m_UseCache && NPT_SUCCEEDED(m_Cache.Get(device->GetUUID(), object_id, list))) return NPT_SUCCESS; do { PLT_BrowseDataReference browse_data(new PLT_BrowseData()); // send off the browse packet. Note that this will // not block. There is a call to WaitForResponse in order // to block until the response comes back. res = BrowseSync( browse_data, device, (const char*)object_id, index, metadata?1:30, // DLNA recommendations for browsing children is no more than 30 at a time metadata); NPT_CHECK_LABEL_WARNING(res, done); if (NPT_FAILED(browse_data->res)) { res = browse_data->res; NPT_CHECK_LABEL_WARNING(res, done); } if (browse_data->info.items->GetItemCount() == 0) break; if (list.IsNull()) { list = browse_data->info.items; } else { list->Add(*browse_data->info.items); // clear the list items so that the data inside is not // cleaned up by PLT_MediaItemList dtor since we copied // each pointer into the new list. browse_data->info.items->Clear(); } // stop now if our list contains exactly what the server said it had. // Note that the server could return 0 if it didn't know how many items were // available. In this case we have to continue browsing until // nothing is returned back by the server. // Unless we were told to stop after reaching a certain amount to avoid // length delays if ((browse_data->info.tm && browse_data->info.tm == list->GetItemCount()) || (max_results && list->GetItemCount() >= max_results)) break; // ask for the next chunk of entries index = list->GetItemCount(); } while(1); done: // cache the result if (m_UseCache && NPT_SUCCEEDED(res) && !list.IsNull() && list->GetItemCount()) { m_Cache.Put(device->GetUUID(), object_id, list); } // clear entire cache data for device if failed, the device could be gone if (NPT_FAILED(res) && m_UseCache) m_Cache.Clear(device->GetUUID()); return res; }
/*---------------------------------------------------------------------- | PLT_SyncMediaBrowser::Browse +---------------------------------------------------------------------*/ NPT_Result PLT_SyncMediaBrowser::Browse(PLT_DeviceDataReference& device, const char* object_id, PLT_MediaObjectListReference& list) { NPT_Result res = NPT_FAILURE; NPT_Int32 index = 0; // reset output params list = NULL; // look into cache first if (m_UseCache && NPT_SUCCEEDED(m_Cache.Get(device->GetUUID(), object_id, list))) return NPT_SUCCESS; do { PLT_BrowseDataReference browse_data(new PLT_BrowseData()); // send off the browse packet. Note that this will // not block. There is a call to WaitForResponse in order // to block until the response comes back. res = Browse(browse_data, device, (const char*)object_id, index, 1024, false, "*", ""); NPT_CHECK_LABEL_WARNING(res, done); if (NPT_FAILED(browse_data->res)) { res = browse_data->res; NPT_CHECK_LABEL_WARNING(res, done); } if (browse_data->info.items->GetItemCount() == 0) break; if (list.IsNull()) { list = browse_data->info.items; } else { list->Add(*browse_data->info.items); // clear the list items so that the data inside is not // cleaned up by PLT_MediaItemList dtor since we copied // each pointer into the new list. browse_data->info.items->Clear(); } // stop now if our list contains exactly what the server said it had if (browse_data->info.tm && browse_data->info.tm == list->GetItemCount()) break; // ask for the next chunk of entries index = list->GetItemCount(); } while(1); done: // cache the result if (m_UseCache && NPT_SUCCEEDED(res) && !list.IsNull() && list->GetItemCount()) { m_Cache.Put(device->GetUUID(), object_id, list); } // clear entire cache data for device if failed, the device could be gone if (NPT_FAILED(res) && m_UseCache) m_Cache.Clear(device->GetUUID()); return res; }