Enlightenment CVS committal Author : moom16 Project : e17 Module : apps/eclair
Dir : e17/apps/eclair/src Modified Files: eclair.c eclair.h eclair_callbacks.c eclair_cover.c eclair_media_file.c eclair_meta_tag.c eclair_playlist.c eclair_private.h Log Message: * Should solve the http error code 400 * Some code enhancements: replace all the: if (ptr1) { if (ptr1->ptr2) ... } by: if (ptr1 && ptr1->ptr2) ... * Inititialize the emotion object on the start of eclair to speed up the first play =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -3 -r1.8 -r1.9 --- eclair.c 3 May 2005 20:36:33 -0000 1.8 +++ eclair.c 4 May 2005 21:36:50 -0000 1.9 @@ -17,6 +17,7 @@ #include "eclair_config.h" #include "eclair_args.h" +static void *_eclair_video_init_thread(void *param); static void _eclair_gui_create_window(Eclair *eclair); static void _eclair_video_create_window(Eclair *eclair); @@ -63,7 +64,10 @@ eclair_subtitles_init(&eclair->subtitles); eclair_meta_tag_init(&eclair->meta_tag_manager, eclair); eclair_cover_init(&eclair->cover_manager, eclair); - eclair_update_current_file_info(eclair, NULL); + eclair_update_current_file_info(eclair); + + eclair->video_initialized = 0; + pthread_create(&eclair->video_init_thread, NULL, _eclair_video_init_thread, eclair); for (l = filenames; l; l = l->next) eclair_playlist_add_media_file(&eclair->playlist, (char *)l->data); @@ -100,9 +104,7 @@ char time_elapsed[10] = ""; double position, length; - if (!eclair) - return; - if (!eclair->video_object || !eclair->gui_object) + if (!eclair || !eclair->video_object || !eclair->gui_object) return; length = emotion_object_play_length_get(eclair->video_object); @@ -130,17 +132,20 @@ } //Update the gui infos about the current media file -void eclair_update_current_file_info(Eclair *eclair, Eclair_Media_File *current_file) +void eclair_update_current_file_info(Eclair *eclair) { char *window_title; char *artist_title_string; const char *filename; + Eclair_Media_File *current_file; if (!eclair) return; - + + current_file = eclair_playlist_current_media_file(&eclair->playlist); + //Update the name of the current file - if (eclair->gui_object) + if (eclair->gui_object && eclair->video_initialized) { if (current_file) { @@ -161,17 +166,12 @@ //Update the title of the video window if (eclair->video_window) { - if (current_file) + if (current_file && current_file->path) { - if (current_file->path) - { - window_title = (char *)malloc(strlen(current_file->path) + strlen("eclair: ") + 1); - sprintf(window_title, "eclair: %s", current_file->path); - ecore_evas_title_set(eclair->video_window, window_title); - free(window_title); - } - else - ecore_evas_title_set(eclair->video_window, "eclair"); + window_title = (char *)malloc(strlen(current_file->path) + strlen("eclair: ") + 1); + sprintf(window_title, "eclair: %s", current_file->path); + ecore_evas_title_set(eclair->video_window, window_title); + free(window_title); } else ecore_evas_title_set(eclair->video_window, "eclair"); @@ -190,19 +190,14 @@ { char *current_path = NULL; - if (!eclair) - return; - if (!eclair->gui_object || !eclair->gui_cover) + if (!eclair || !eclair->gui_object || !eclair->gui_cover) return; evas_object_image_file_get(eclair->gui_cover, ¤t_path, NULL); if (!current_path && !cover_path) return; - if (current_path && cover_path) - { - if (strcmp(current_path, cover_path) == 0) + if (current_path && cover_path && (strcmp(current_path, cover_path) == 0)) return; - } if (eclair->gui_previous_cover) { @@ -236,9 +231,7 @@ //Set the scroll percent of the playlist container void eclair_playlist_container_scroll_percent_set(Eclair *eclair, double percent) { - if (!eclair) - return; - if (!eclair->playlist_container) + if (!eclair || !eclair->playlist_container) return; esmart_container_scroll_percent_set(eclair->playlist_container, percent); @@ -254,7 +247,7 @@ Evas_Coord container_height; float hidden_items; - if (!eclair || !eclair->playlist_container || !eclair->gui_object || eclair->playlist_entry_height <= 0) + if (!eclair || !eclair->playlist_container || !eclair->gui_object || (eclair->playlist_entry_height <= 0)) return; entries_list = esmart_container_elements_get(eclair->playlist_container); @@ -268,7 +261,7 @@ percent += num_entries / hidden_items; if (percent > 1.0) percent = 1.0; - if (percent < 0.0) + else if (percent < 0.0) percent = 0.0; eclair_playlist_container_scroll_percent_set(eclair, percent); } @@ -322,9 +315,7 @@ { int video_width, video_height; - if (!eclair || !path) - return; - if (!eclair->video_window || !eclair->video_object) + if (!eclair || !path || !eclair->video_window || !eclair->video_object) return; emotion_object_file_set(eclair->video_object, path); @@ -386,9 +377,7 @@ //Pause the playback void eclair_pause(Eclair *eclair) { - if (!eclair) - return; - if (eclair->state != ECLAIR_PLAYING) + if (!eclair || (eclair->state != ECLAIR_PLAYING)) return; emotion_object_play_set(eclair->video_object, 0); @@ -399,9 +388,7 @@ //Play the current file if state is STOP or resume if state is PAUSE void eclair_play(Eclair *eclair) { - if (!eclair) - return; - if (!eclair->video_window) + if (!eclair || !eclair->video_window) return; if (eclair->state == ECLAIR_PAUSE) @@ -453,20 +440,16 @@ //Get the media progress rate double eclair_progress_rate_get(Eclair *eclair) { - if (!eclair) - return 0.0; - if (!eclair->video_object) + if (!eclair || !eclair->video_object) return 0.0; - return eclair_position_get(eclair) / emotion_object_play_length_get(eclair->video_object); + return (eclair_position_get(eclair) / emotion_object_play_length_get(eclair->video_object)); } //Set the media progress rate void eclair_progress_rate_set(Eclair *eclair, double progress_rate) { - if (!eclair) - return; - if (!eclair->video_object) + if (!eclair || !eclair->video_object) return; eclair_position_set(eclair, progress_rate * emotion_object_play_length_get(eclair->video_object)); @@ -475,9 +458,7 @@ //Get the media position in seconds double eclair_position_get(Eclair *eclair) { - if (!eclair) - return 0.0; - if (!eclair->video_object) + if (!eclair || !eclair->video_object) return 0.0; if (eclair->seek_to_pos < 0.0) @@ -491,9 +472,7 @@ { double media_length; - if (!eclair) - return; - if (!eclair->video_object) + if (!eclair || !eclair->video_object) return; media_length = emotion_object_play_length_get(eclair->video_object); @@ -506,6 +485,25 @@ emotion_object_position_set(eclair->video_object, eclair->seek_to_pos); } +//Initialize the video object +static void *_eclair_video_init_thread(void *param) +{ + Eclair *eclair = (Eclair *)param; + + if (!eclair || !eclair->video_object) + return NULL; + + if (eclair->gui_object) + edje_object_part_text_set(eclair->gui_object, "current_media_name", "Initializing..."); + + emotion_object_init(eclair->video_object); + eclair->video_initialized = 1; + + eclair_update_current_file_info(eclair); + + return NULL; +} + //Create the gui window and load the interface static void _eclair_gui_create_window(Eclair *eclair) { =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- eclair.h 3 May 2005 20:36:33 -0000 1.5 +++ eclair.h 4 May 2005 21:36:50 -0000 1.6 @@ -8,7 +8,7 @@ void eclair_shutdown(Eclair *eclair); void eclair_update(Eclair *eclair); void *eclair_file_chooser_thread(void *param); -void eclair_update_current_file_info(Eclair *eclair, Eclair_Media_File *file); +void eclair_update_current_file_info(Eclair *eclair); void eclair_playlist_container_scroll(Eclair *eclair, int num_entries); void eclair_playlist_container_scroll_percent_set(Eclair *eclair, double percent); void eclair_gui_cover_set(Eclair *eclair, const char *cover_path); =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_callbacks.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- eclair_callbacks.c 3 May 2005 20:36:33 -0000 1.7 +++ eclair_callbacks.c 4 May 2005 21:36:50 -0000 1.8 @@ -35,9 +35,7 @@ { Eclair *eclair = (Eclair *)data; - if (!eclair) - return; - if (!eclair->gui_object || !eclair->video_object) + if (!eclair || !eclair->gui_object || !eclair->video_object) return; edje_object_part_drag_value_set(eclair->gui_object, "volume_bar_drag", emotion_object_audio_volume_get(eclair->video_object), 0); @@ -86,7 +84,6 @@ evas_object_move(eclair->video_object, X, Y); evas_object_resize(eclair->video_object, video_width, video_height); } - if (eclair->black_background) { evas_object_move(eclair->black_background, 0, 0); @@ -234,9 +231,7 @@ { Eclair *eclair = (Eclair *)data; - if (!eclair) - return; - if (!eclair->gui_window) + if (!eclair || !eclair->gui_window) return; ecore_evas_iconified_set(eclair->gui_window, 1); @@ -293,9 +288,7 @@ Eclair *eclair = (Eclair *)data; double y; - if (!eclair) - return; - if (!eclair->gui_object) + if (!eclair || !eclair->gui_object) return; edje_object_part_drag_value_get(eclair->gui_object, "playlist_scrollbar_button", NULL, &y); @@ -307,7 +300,7 @@ { Eclair *eclair = (Eclair *)data; - if (!eclair->playlist_container) + if (!eclair || !eclair->playlist_container) return; if (strcmp(emission, "playlist_scroll_down_start") == 0) @@ -324,7 +317,7 @@ Eclair *eclair = (Eclair *)data; Evas_Event_Mouse_Wheel *event = (Evas_Event_Mouse_Wheel *)event_info; - eclair_playlist_container_scroll(eclair, event->z); + eclair_playlist_container_scroll(eclair, event->z); } //Called when the gui send a message =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_cover.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- eclair_cover.c 3 May 2005 20:36:33 -0000 1.5 +++ eclair_cover.c 4 May 2005 21:36:50 -0000 1.6 @@ -34,7 +34,7 @@ static int _eclair_cover_connect_to_host(const struct hostent *host); static Evas_Bool _eclair_cover_receive_next_packet(int socket_fd, char **packet, int *length); static int _eclair_cover_extract_http_body(char *packet, int packet_length, char **body); -static int _eclair_cover_fetch(const char *url, const struct hostent *he, char **data); +static int _eclair_cover_fetch(const char *url, char **data); static char *_eclair_cover_build_path_from_filepath(Eclair_Cover_Manager *cover_manager, const char *file_path, const char *cover_extension); static char *_eclair_cover_build_path_from_artist_album(Eclair_Cover_Manager *cover_manager, const char *artist, const char *album, const char *cover_extension); @@ -58,7 +58,6 @@ cover_manager->cover_files_to_treat = NULL; cover_manager->not_in_amazon_db = NULL; cover_manager->eclair = eclair; - cover_manager->amazon_he = NULL; cover_manager->cover_delete_thread = 0; pthread_cond_init(&cover_manager->cover_cond, NULL); pthread_mutex_init(&cover_manager->cover_mutex, NULL); @@ -74,7 +73,6 @@ if (!cover_manager) return; - free(cover_manager->amazon_he); for (l = cover_manager->not_in_amazon_db; l; l = l->next) { if ((album = (Eclair_Cover_Not_In_DB_Album *)l->data)) @@ -96,12 +94,11 @@ //Add a media file to the list of files to treat void eclair_cover_add_file_to_treat(Eclair_Cover_Manager *cover_manager, Eclair_Media_File *media_file) { - if (!cover_manager || !media_file) - return; - if (cover_manager->cover_delete_thread) + if (!cover_manager || !media_file || cover_manager->cover_delete_thread) return; - while (cover_manager->cover_add_state != ECLAIR_IDLE); + while (cover_manager->cover_add_state != ECLAIR_IDLE) + printf("cover: Waiting IDLE: %d\n", cover_manager->cover_add_state); cover_manager->cover_add_state = ECLAIR_ADDING_FILE_TO_ADD; cover_manager->cover_files_to_add = evas_list_append(cover_manager->cover_files_to_add, media_file); cover_manager->cover_add_state = ECLAIR_IDLE; @@ -117,9 +114,7 @@ Evas_List *l, *next; Eclair_Media_File *current_file; - if (!cover_manager) - return NULL; - if (!(eclair = cover_manager->eclair)) + if (!cover_manager || !(eclair = cover_manager->eclair)) return NULL; pthread_mutex_lock(&cover_manager->cover_mutex); @@ -138,7 +133,8 @@ //Add the new files to the list of files to treat if (cover_manager->cover_files_to_add) { - while (cover_manager->cover_add_state != ECLAIR_IDLE); + while (cover_manager->cover_add_state != ECLAIR_IDLE) + printf("cover: Waiting IDLE2: %d\n", cover_manager->cover_add_state); cover_manager->cover_add_state = ECLAIR_ADDING_FILE_TO_TREAT; for (l = cover_manager->cover_files_to_add; l; l = next) { @@ -226,9 +222,7 @@ Evas_List *l; Eclair_Cover_Not_In_DB_Album *not_in_db_album; - if (!cover_manager || !artist || !album) - return NULL; - if (strlen(artist) <= 0 || strlen(album) <= 0) + if (!cover_manager || !artist || !album || !(strlen(artist) <= 0) || !(strlen(album) <= 0)) return NULL; //Check if we already perform a search on this album and if amazon answered it doesn't have this album in database @@ -242,17 +236,6 @@ return NULL; } - //Resolve amazone hostname - if (!cover_manager->amazon_he) - { - struct hostent *he; - if ((he = gethostbyname(amazon_hostname))) - { - cover_manager->amazon_he = (struct hostent *)malloc(sizeof(struct hostent)); - memcpy(cover_manager->amazon_he, he, sizeof(struct hostent)); - } - } - //Get the ASIN of the album keywords = (char *)malloc(strlen(artist) + strlen(album) + 2); sprintf(keywords, "%s %s", artist, album); @@ -263,7 +246,7 @@ free(converted_keywords); if (cover_manager->cover_delete_thread) return NULL; - body_length = _eclair_cover_fetch(url, cover_manager->amazon_he, &body); + body_length = _eclair_cover_fetch(url, &body); if (body_length <= 0) { fprintf(stderr, "Cover: Unable to download cover from amazon.com\n"); @@ -292,7 +275,7 @@ xmlFree(ASIN); if (cover_manager->cover_delete_thread) return NULL; - body_length = _eclair_cover_fetch(url, cover_manager->amazon_he, &body); + body_length = _eclair_cover_fetch(url, &body); if (body_length <= 0) { fprintf(stderr, "Cover: Unable to download cover from amazon.com\n"); @@ -327,7 +310,7 @@ xmlFree(cover_url); return NULL; } - body_length = _eclair_cover_fetch(cover_url, NULL, &body); + body_length = _eclair_cover_fetch(cover_url, &body); xmlFree(cover_url); if (body_length <= 0) { @@ -404,14 +387,13 @@ //Try to fetch the file stored at url on host he (may be NULL) and put the data into data //data has to be freed if success //Return the length of the data (negative if failed) -static int _eclair_cover_fetch(const char *url, const struct hostent *he, char **data) +static int _eclair_cover_fetch(const char *url, char **data) { const char *host_start; const char *url_abs_path; char request[MAX_REQUEST_SIZE]; char *host, *packet, *body; int packet_length, body_length; - struct in_addr in; int socket_fd; if (!url || !data) @@ -430,26 +412,13 @@ return -1; } - if (!he) + host = (char *)malloc(url_abs_path - host_start + 1); + strncpy(host, host_start, url_abs_path - host_start); + host[url_abs_path - host_start] = 0; + if ((socket_fd = _eclair_cover_connect_to_hostname(host)) < 0) { - host = (char *)malloc(url_abs_path - host_start + 1); - strncpy(host, host_start, url_abs_path - host_start); - host[url_abs_path - host_start] = 0; - if ((socket_fd = _eclair_cover_connect_to_hostname(host)) < 0) - { - free(host); - return -1; - } - } - else - { - memcpy(&in, he->h_addr, he->h_length); - host = strdup(inet_ntoa(in)); - if ((socket_fd = _eclair_cover_connect_to_host(he)) < 0) - { - free(host); - return -1; - } + free(host); + return -1; } sprintf(request, "GET %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: eclair\r\n\r\n", url_abs_path, host); @@ -562,9 +531,7 @@ char *cover_path, *ext_start, *filename_without_ext; const char *filename; - if (!cover_manager || !file_path || !cover_extension) - return NULL; - if (!cover_manager->eclair) + if (!cover_manager || !file_path || !cover_extension || !cover_manager->eclair) return NULL; filename = eclair_utils_path_to_filename(file_path); @@ -585,10 +552,8 @@ { char *filename, *path, *c; - if (!cover_manager || !artist || !album || !cover_extension) + if (!cover_manager || !artist || !album || !cover_extension || !cover_manager->eclair) return NULL; - if (!cover_manager->eclair) - return NULL; filename = (char *)malloc(strlen(artist) + strlen(album) + strlen(cover_extension) + 3); sprintf(filename, "%s_%s.%s", artist, album, cover_extension); =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_media_file.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- eclair_media_file.c 3 May 2005 20:36:33 -0000 1.4 +++ eclair_media_file.c 4 May 2005 21:36:50 -0000 1.5 @@ -64,5 +64,5 @@ //If the media file is the current, we also update gui infos if (media_file == eclair_playlist_current_media_file(&eclair->playlist)) - eclair_update_current_file_info(eclair, media_file); + eclair_update_current_file_info(eclair); } =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_meta_tag.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- eclair_meta_tag.c 3 May 2005 20:36:33 -0000 1.4 +++ eclair_meta_tag.c 4 May 2005 21:36:50 -0000 1.5 @@ -44,7 +44,8 @@ if (meta_tag_manager->meta_tag_delete_thread) return; - while (meta_tag_manager->meta_tag_add_state != ECLAIR_IDLE); + while (meta_tag_manager->meta_tag_add_state != ECLAIR_IDLE) + printf("meta tag: Waiting IDLE %d\n", meta_tag_manager->meta_tag_add_state); meta_tag_manager->meta_tag_add_state = ECLAIR_ADDING_FILE_TO_ADD; meta_tag_manager->meta_tag_files_to_add = evas_list_append(meta_tag_manager->meta_tag_files_to_add, media_file); meta_tag_manager->meta_tag_add_state = ECLAIR_IDLE; @@ -117,7 +118,8 @@ //Add the new files to the list of files to treat if (meta_tag_manager->meta_tag_files_to_add) { - while (meta_tag_manager->meta_tag_add_state != ECLAIR_IDLE); + while (meta_tag_manager->meta_tag_add_state != ECLAIR_IDLE) + printf("meta tag: Waiting IDLE2 %d\n", meta_tag_manager->meta_tag_add_state); meta_tag_manager->meta_tag_add_state = ECLAIR_ADDING_FILE_TO_TREAT; for (l = meta_tag_manager->meta_tag_files_to_add; l; l = next) { =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_playlist.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- eclair_playlist.c 3 May 2005 20:36:33 -0000 1.4 +++ eclair_playlist.c 4 May 2005 21:36:50 -0000 1.5 @@ -166,31 +166,22 @@ if (!playlist) return; - if ((media_file = eclair_playlist_current_media_file(playlist))) - { - if (media_file->playlist_entry) - edje_object_signal_emit(media_file->playlist_entry, "signal_unset_current", "eclair_bin"); - } + if ((media_file = eclair_playlist_current_media_file(playlist)) && media_file->playlist_entry) + edje_object_signal_emit(media_file->playlist_entry, "signal_unset_current", "eclair_bin"); - if ((media_file = evas_list_data(list))) + if ((media_file = evas_list_data(list)) && media_file->playlist_entry) { - if (media_file->playlist_entry) + edje_object_signal_emit(media_file->playlist_entry, "signal_set_current", "eclair_bin"); + if (playlist->eclair) { - edje_object_signal_emit(media_file->playlist_entry, "signal_set_current", "eclair_bin"); - if (playlist->eclair) - { - //TODO: doesn't work? - if (playlist->eclair->playlist_container) - esmart_container_scroll_to(playlist->eclair->playlist_container, media_file->playlist_entry); - } + //TODO: doesn't work? + if (playlist->eclair->playlist_container) + esmart_container_scroll_to(playlist->eclair->playlist_container, media_file->playlist_entry); } - if (playlist->eclair) - eclair_update_current_file_info(playlist->eclair, media_file); } - else if (playlist->eclair) - eclair_update_current_file_info(playlist->eclair, NULL); playlist->current = list; + eclair_update_current_file_info(playlist->eclair); } //Set the media file which is just before the active media file as the active media file =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_private.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- eclair_private.h 3 May 2005 20:36:33 -0000 1.7 +++ eclair_private.h 4 May 2005 21:36:50 -0000 1.8 @@ -43,7 +43,6 @@ Evas_List *not_in_amazon_db; Evas_Bool cover_delete_thread; Eclair *eclair; - struct hostent *amazon_he; pthread_cond_t cover_cond; pthread_mutex_t cover_mutex; pthread_t cover_thread; @@ -69,7 +68,8 @@ char *album; char *genre; char *comment; - int length, year, track; + int length, track; + short year; Evas_Object *playlist_entry; }; @@ -115,6 +115,8 @@ Evas_Object *black_background; Evas_Object *subtitles_object; Eclair_Engine video_engine; + pthread_t video_init_thread; + Evas_Bool video_initialized; //Gui related vars Ecore_Evas *gui_window; ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. Get your fingers limbered up and give it your best shot. 4 great events, 4 opportunities to win big! Highest score wins.NEC IT Guy Games. Play to win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs