--- commit 75b8244ca49c0f88e8a8d8d1f0ff015385be9dce tree 9843d2b401e0edfcc3ce586ece824f3dbe970545 parent b61cf121b37c9e60fbce01c33e496957501b264e author Mike Drons Wed, 31 Jan 2007 23:14:09 -0500 committer Mike Drons Wed, 31 Jan 2007 23:14:09 -0500 include/cmyth.h | 2 + libs/libcmyth/bookmark.c | 5 ++- libs/libcmyth/mythtv_mysql.c | 73 +++++++++++++++++++++++++++++++++++++++++- src/mythtv.c | 28 ++++++++++++++++ src/video.c | 2 + 5 files changed, 106 insertions(+), 4 deletions(-) diff --git a/include/cmyth.h b/include/cmyth.h index ed84469..b10aea0 100644 --- a/include/cmyth.h +++ b/include/cmyth.h @@ -977,6 +977,8 @@ extern cmyth_freespace_t cmyth_freespace * ------- */ extern long long cmyth_get_bookmark(cmyth_conn_t conn, cmyth_proginfo_t prog); +extern int cmyth_get_bookmark_offset(cmyth_database_t db, long chanid, long long mark); +extern int cmyth_get_bookmark_mark(cmyth_database_t, cmyth_proginfo_t, long long); extern int cmyth_set_bookmark(cmyth_conn_t conn, cmyth_proginfo_t prog, long long bookmark); extern cmyth_commbreaklist_t cmyth_commbreaklist_create(void); diff --git a/libs/libcmyth/bookmark.c b/libs/libcmyth/bookmark.c index 1e0c0be..3ed6a51 100644 --- a/libs/libcmyth/bookmark.c +++ b/libs/libcmyth/bookmark.c @@ -33,7 +33,7 @@ long long cmyth_get_bookmark(cmyth_conn_ long long ret; int count; char start_ts_dt[CMYTH_TIMESTAMP_LEN + 1]; - cmyth_datetime_to_string(start_ts_dt, prog->proginfo_start_ts); + cmyth_datetime_to_string(start_ts_dt, prog->proginfo_rec_start_ts); buf = alloca(len); if (!buf) { return -ENOMEM; @@ -81,13 +81,14 @@ int cmyth_set_bookmark(cmyth_conn_t conn int ret; int count; char start_ts_dt[CMYTH_TIMESTAMP_LEN + 1]; - cmyth_datetime_to_string(start_ts_dt, prog->proginfo_start_ts); + cmyth_datetime_to_string(start_ts_dt, prog->proginfo_rec_start_ts); buf = alloca(len); if (!buf) { return -ENOMEM; } sprintf(buf,"%s %ld %s %lld %lld","SET_BOOKMARK",prog->proginfo_chanId, start_ts_dt, bookmark >> 32,(bookmark & 0xffffffff)); +fprintf(stderr, "MIKE :%s buf = %s\n",__FUNCTION__,buf); pthread_mutex_lock(&mutex); if ((err = cmyth_send_message(conn,buf)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, diff --git a/libs/libcmyth/mythtv_mysql.c b/libs/libcmyth/mythtv_mysql.c index 6afe26a..0d30418 100644 --- a/libs/libcmyth/mythtv_mysql.c +++ b/libs/libcmyth/mythtv_mysql.c @@ -571,6 +571,76 @@ fill_program_recording_status(cmyth_conn return err; } +int +cmyth_get_bookmark_mark(cmyth_database_t db, cmyth_proginfo_t prog, long long bk) +{ + MYSQL_RES *res = NULL; + MYSQL_ROW row; + const char *query_str = "SELECT mark FROM recordedseek WHERE chanid = ? AND offset>= ? AND type = 6 ORDER by MARK ASC LIMIT 0,1;"; + int rows = 0; + int mark=0; + char start_ts_dt[CMYTH_TIMESTAMP_LEN + 1]; + cmyth_mysql_query_t * query; + cmyth_datetime_to_string(start_ts_dt, prog->proginfo_rec_start_ts); + query = cmyth_mysql_query_create(db,query_str); + if (cmyth_mysql_query_param_long(query, prog->proginfo_chanId) < 0 + || cmyth_mysql_query_param_long(query, bk) < 0 + ) { + cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__); + cmyth_release(query); + return -1; + } + fprintf(stderr, "MIKE : query = %s\n",cmyth_mysql_query_string(query)); + res = cmyth_mysql_query_result(query); + cmyth_release(query); + if (res == NULL) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s, finalisation/execution of query failed!\n", __FUNCTION__); + return -1; + } + while ((row = mysql_fetch_row(res))) { + mark = safe_atoi(row[0]); + fprintf (stderr, "rows=%d offset = %d\n",rows,mark); + rows++; + } + + mysql_free_result(res); + return mark; +} + +int +cmyth_get_bookmark_offset(cmyth_database_t db, long chanid, long long mark) +{ + MYSQL_RES *res = NULL; + MYSQL_ROW row; + const char *query_str = "SELECT * FROM recordedseek WHERE chanid = ? AND mark= ?;"; + int offset=0; + int rows = 0; + cmyth_mysql_query_t * query; + query = cmyth_mysql_query_create(db,query_str); + if (cmyth_mysql_query_param_long(query, chanid) < 0 + || cmyth_mysql_query_param_long(query, mark) < 0 + ) { + cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__); + cmyth_release(query); + return -1; + } + fprintf(stderr, "MIKE : query = %s\n",cmyth_mysql_query_string(query)); + res = cmyth_mysql_query_result(query); + cmyth_release(query); + if (res == NULL) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s, finalisation/execution of query failed!\n", __FUNCTION__); + return -1; + } + while ((row = mysql_fetch_row(res))) { + offset = safe_atoi(row[3]); + fprintf (stderr, "rows=%d offset = %d\n",rows,offset); + rows++; + } + + mysql_free_result(res); + return offset; +} + int cmyth_mysql_get_commbreak_list(cmyth_database_t db, int chanid, char * start_ts_dt, cmyth_commbreaklist_t breaklist) { @@ -591,7 +661,7 @@ cmyth_mysql_get_commbreak_list(cmyth_dat cmyth_release(query); return -1; } - + fprintf(stderr, "MIKE : query = %s\n",cmyth_mysql_query_string(query)); res = cmyth_mysql_query_result(query); cmyth_release(query); if (res == NULL) { @@ -629,6 +699,7 @@ cmyth_mysql_get_commbreak_list(cmyth_dat commbreak->end_mark = safe_atoll(row[1]); commbreak->end_offset = safe_atoll(row[2]); breaklist->commbreak_list[rows] = commbreak; + fprintf (stderr, "i=%d rows=%d endoffset = %ld mark=%ld\n",i,rows,commbreak->end_offset,commbreak->end_mark); i = 0; rows++; } diff --git a/src/mythtv.c b/src/mythtv.c index 9af809e..2698c4d 100644 --- a/src/mythtv.c +++ b/src/mythtv.c @@ -184,6 +184,11 @@ mythtv_video_key(char key) { int rc = 0; int breakidx; + long long mark,bk; + long bookmark,chanid; + int offset=0; + int dbmark=0; + cmyth_conn_t ctrl=cmyth_hold(control); switch (key) { case MVPW_KEY_SKIP: @@ -204,6 +209,29 @@ mythtv_video_key(char key) fprintf(stderr, "Not in commbreak. Reverting to standard replay.\n"); } break; + case MVPW_KEY_BLUE: + mark=cmyth_get_bookmark(ctrl,current_prog); + mark=(mark/15)+1; + chanid=cmyth_proginfo_chan_id(current_prog); + fprintf(stderr,"chanid %ld\n",chanid); + offset = cmyth_get_bookmark_offset(mythtv_database,chanid,mark); + fprintf(stderr,"Jumping to bookmark %qd : offset %d\n",mark,offset); + seek_to(offset); + rc=1; + break; + case MVPW_KEY_YELLOW: + bookmark = video_functions->seek(0, SEEK_CUR); + bk= bookmark; + fprintf (stderr,"new bookmark=%ld : bk=%qd\n",bookmark,bk); + dbmark=cmyth_get_bookmark_mark(mythtv_database,current_prog,bk); + fprintf (stderr,"mark = %d\n",dbmark); + dbmark = (dbmark-1)*15; + fprintf (stderr,"mark = %d\n",dbmark); + cmyth_set_bookmark(ctrl, current_prog, dbmark ); + cmyth_dbg(CMYTH_DBG_DEBUG, "retrieved saved, value: %qd \n",bookmark); + cmyth_release(ctrl); + rc=1; + break; } return rc; diff --git a/src/video.c b/src/video.c index 3530bc1..ba44f32 100644 --- a/src/video.c +++ b/src/video.c @@ -507,7 +507,7 @@ void seek_to(long long seek_offset) { long long offset; - +fprintf(stderr, "MIKE : %s :offset=%qd\n",__FUNCTION__,seek_offset); if (video_functions->seek == NULL) { fprintf(stderr, "cannot seek on this video!\n"); return;