/* * method: FIFO or LIFO; */ void msg_put(QUEUE *entry, MSG *msg, U8 method) { if ((entry == NULL) || (msg == NULL) || (entry->count > entry->length)) OS_LOG("Message put in queue error\n"); TCB *tcb_tmp; U32 cpu_sr = interrupt_disable(); /*Check tasks block on the message queue list*/ if (!is_list_last(&entry->list)) { tcb_tmp = list_entry(entry->list.next, TCB, list); msg_block_queue_delete(tcb_tmp); prio_ready_queue_insert_head(tcb_tmp); } if (entry->count == entry->length) { /*XXX Todo: if queue is full, block the task*/ // block_queue(new_task); OS_LOG("Message queue overflow\n"); }else entry->count++; if (method == FIFO) list_insert_behind(&entry->msg_head, &msg->list); else /*Last come first server.*/ list_insert_spec(&entry->msg_head, &msg->list); interrupt_enable(cpu_sr); /*Maybe don't schedule?*/ schedule(); }
void os_bind_core(int64_t bind_core_id) { if (-1 == bind_core_id) { // need not bind } else { cpu_set_t cpuset; CPU_ZERO(&cpuset); CPU_SET(bind_core_id, &cpuset); int tmp_ret = 0; if (0 != (tmp_ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset))) { OS_LOG(WARN, "bind_core fail, bind_core_id=%ld ret=%d", bind_core_id, tmp_ret); } else { OS_LOG(INFO, "bind_core succ, bind_core_id=%ld", bind_core_id); } } }
bool TDvbJanssonParser::SetProfiles(std::string& profiles) { bool ret(true); json_error_t error; json_t* json = json_loads(profiles.c_str(), 0, &error); if (json) { if (json_dump_file(json, DvbConfigProfileFile.c_str(), JSON_INDENT(2)|JSON_ENSURE_ASCII|JSON_PRESERVE_ORDER) == -1) { OS_LOG(DVB_ERROR, "%s:%d: json_dump_file(%s) failed\n", __FUNCTION__, __LINE__, DvbConfigProfileFile.c_str()); ret = false; } json_decref(json); } else { OS_LOG(DVB_ERROR, "%s:%d: json_loads() failed, error = %s\n", __FUNCTION__, __LINE__, error.text); ret = false; } return ret; }
std::string TDvbJanssonParser::GetProfiles() { std::string res; json_error_t error; json_t* json = json_load_file(DvbConfigProfileFile.c_str(), 0, &error); if (json) { res = std::string(json_dumps(json, JSON_INDENT(2)|JSON_ENSURE_ASCII|JSON_PRESERVE_ORDER)); json_decref(json); } else { OS_LOG(DVB_ERROR, "%s:%d: json_load_file(%s) failed, error = %s\n", __FUNCTION__, __LINE__, DvbConfigProfileFile.c_str(), error.text); } return res; }
void TestList(void) { OS_List os_test_list; OS_ListItem* item_l_p; OS_ListItem* item_next_p; // Init list. srand(rand()); OS_ListInit(&os_test_list); TEST_ASSERT_TRUE(OS_LIST_IS_INITIALISED(&os_test_list)); // Add items to the list. for (SIZE i = 0; i < 0x10; ++i) { item_l_p = OS_ListItemCreate(); if (OS_NULL == item_l_p) { OS_TRACE(D_CRITICAL, "No memory!\n", OS_NULL); } OS_LIST_ITEM_VALUE_SET(item_l_p, (OS_Value)(rand() % U8_MAX)); OS_ListAppend(&os_test_list, item_l_p); } OS_LOG(D_DEBUG, "Initial list:"); TestListLog(&os_test_list); // Sort the list. TestListSort(&os_test_list, SORT_ASCENDING); OS_LOG(D_DEBUG, "List sorted by ascending:"); TestListLog(&os_test_list); TestListSort(&os_test_list, SORT_DESCENDING); OS_LOG(D_DEBUG, "List sorted by descending:"); TestListLog(&os_test_list); OS_TRACE(D_DEBUG, "\n", OS_NULL); // Clean up. item_l_p = OS_LIST_ITEM_NEXT_GET((OS_ListItem*)&OS_LIST_ITEM_LAST_GET(&os_test_list)); while (OS_TRUE != OS_LIST_IS_EMPTY(&os_test_list)) { item_next_p = OS_LIST_ITEM_NEXT_GET(item_l_p); OS_ListItemDelete(item_l_p); item_l_p = item_next_p; } }
int main(int argc, char *argv[]) { if (kxplayer_initialize() != 0) { OS_LOG(os_log_error, "unable to initialize kxplayer."); return -1; } os_log_setlevel(os_log_trace); struct os_log_backend* console = os_log_backend_create(os_log_console_interface(), NULL); os_log_add_backend(console); struct kxplayer_agent_option option; option.start_callback = start; option.receive_callback = receive; option.finish_callback = NULL; option.userdata = NULL; struct kxplayer_agent* agent = kxplayer_agent_create(&option); if (agent == NULL) { OS_LOG(os_log_error, "unable to create agent."); return -1; } if (kxplayer_agent_open(agent, PLAY_URI) != 0) { OS_LOG(os_log_error, "unable to open uri %s.", PLAY_URI); return -1; } os_sleep(5000); kxplayer_agent_open(agent, MP3_FILE); os_sleep(999999); kxplayer_agent_stop(agent); kxplayer_terminate(); return 0; }
void msg_queue_create(QUEUE *entry, U32 length, U8 *name) { if ((entry == NULL) || (length <= 0)) OS_LOG("Message create error\n"); U32 cpu_sr = interrupt_disable(); /*Init message block queue*/ msg_block_queue_init(entry); /*Build message queue*/ list_init(&entry->msg_head); entry->length = length; entry->count = 0; entry->name = name; interrupt_enable(cpu_sr); }
std::vector<std::shared_ptr<TDvbStorageNamespace::InbandTableInfoStruct>> TDvbJanssonParser::GetInbandTableInfo(std::string& profile) { std::vector<std::shared_ptr<TDvbStorageNamespace::InbandTableInfoStruct>> ret; OS_LOG(DVB_DEBUG, "%s:%d: called\n", __FUNCTION__, __LINE__); json_error_t error; json_t* json = json_load_file(DvbConfigProfileFile.c_str(), 0, &error); if (!json) { OS_LOG(DVB_ERROR, "%s:%d: json_load_file(%s) failed, error = %s\n", __FUNCTION__, __LINE__, DvbConfigProfileFile.c_str(), error.text); return ret; } // Search for object with name == profile size_t size = json_array_size(json); OS_LOG(DVB_DEBUG, "%s:%d: number of profiles = %d\n", __FUNCTION__, __LINE__, size); for (size_t i = 0; i < size; ++i) { json_t* obj = json_array_get(json, i); if (!obj) { continue; } json_t* name = json_object_get(obj, "name"); if (!name) { continue; } OS_LOG(DVB_DEBUG, "%s:%d: profile = %s\n", __FUNCTION__, __LINE__, json_string_value(name)); if (profile.compare(json_string_value(name)) == 0) { OS_LOG(DVB_DEBUG, "%s:%d: requested profile found\n", __FUNCTION__, __LINE__); // Get "tables" object json_t* tables = json_object_get(obj, "tables"); if (tables) { OS_LOG(DVB_DEBUG, "%s:%d: tables object found\n", __FUNCTION__, __LINE__); // Get "inband" array json_t* inband = json_object_get(tables, "inband"); if (inband) { OS_LOG(DVB_DEBUG, "%s:%d: inband array found\n", __FUNCTION__, __LINE__); // Read table objects size_t num = json_array_size(inband); for (size_t j = 0; j < num; j++) { json_t* t = json_array_get(inband, j); if (!t) { continue; } json_t* v = json_object_get(t, "pid"); if (!v) { continue; } uint16_t pid = json_integer_value(v); v = json_object_get(t, "table_id"); if (!v) { continue; } uint16_t tableId = json_integer_value(v); v = json_object_get(t, "table_id_ext"); if (!v) { continue; } uint16_t extensionId = json_integer_value(v); OS_LOG(DVB_DEBUG, "%s:%d: table (0x%x, 0x%x, 0x%x)\n", __FUNCTION__, __LINE__, pid, tableId, extensionId); ret.emplace_back(new TDvbStorageNamespace::InbandTableInfoStruct(pid, tableId, extensionId)); } } } break; } } json_decref(json); return ret; }
/// Used to output a message on a debug hardware unit - does nothing on a retail unit static void OutputDebugString(const char* string) { OS_LOG(SVC, "%s", string); }
static void receive(void* data, size_t size, void* userdata) { OS_LOG(os_log_debug, "receive data."); }
static int start(struct kxplayer_avcontext* context, void* userdata) { OS_LOG(os_log_debug, "start callback."); return 0; }