00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00032
00033 #ifdef HAVE_CONFIG_H
00034 #include "autoconfig.h"
00035 #endif
00036
00037 #ifdef HAVE_LIBDVDNAV
00038
00039 #include "dvd_handler.h"
00040 #include "string_converter.h"
00041 #include "common.h"
00042 #include "tools.h"
00043 #include "content_manager.h"
00044 #include "config_manager.h"
00045
00046 #include "dvdnav_read.h"
00047
00048 using namespace zmm;
00049
00050 #define DVD "dvd"
00051 #define DVD_TITLE DVD "t"
00052 #define DVD_CHAPTER "ch"
00053 #define DVD_AUDIO_TRACK "at"
00054 #define DVD_DURATION "d"
00055 #define DVD_REST_DURATION "r"
00056 #define DVD_FORMAT "f"
00057 #define DVD_STREAM_ID "i"
00058 #define DVD_COUNT "c"
00059 #define DVD_CHANNELS "l"
00060 #define DVD_SAMPLE_FREQUENCY "q"
00061 #define DVD_LANGUAGE "g"
00062
00063 #define DVD_MIMETYPE DVD "m"
00064
00065 DVDHandler::DVDHandler() : MetadataHandler()
00066 {
00067 }
00068
00069 String DVDHandler::renderKey(dvd_aux_key_names_t name, int title_idx,
00070 int chapter_idx, int audio_track_idx)
00071 {
00072 String key;
00073
00074 switch (name)
00075 {
00076 case DVD_Title:
00077 key = _(DVD_TITLE);
00078 break;
00079 case DVD_Chapter:
00080 key = _(DVD DVD_CHAPTER);
00081 break;
00082 case DVD_AudioTrack:
00083 key = _(DVD DVD_AUDIO_TRACK);
00084 break;
00085 case DVD_AudioStreamID:
00086 key = _(DVD DVD_STREAM_ID);
00087 break;
00088 case DVD_TitleCount:
00089 key = _(DVD_TITLE) + _(DVD_COUNT);
00090 break;
00091 case DVD_TitleDuration:
00092 key = _(DVD_TITLE) + title_idx + _(DVD_DURATION);
00093 break;
00094 case DVD_ChapterCount:
00095 key = _(DVD_TITLE) + title_idx + _(DVD_CHAPTER) + chapter_idx +
00096 _(DVD_COUNT);
00097 break;
00098 case DVD_ChapterDuration:
00099 key = _(DVD_TITLE) + title_idx + _(DVD_CHAPTER) + chapter_idx +
00100 _(DVD_DURATION);
00101 case DVD_ChapterRestDuration:
00102 key = _(DVD_TITLE) + title_idx + _(DVD_CHAPTER) + chapter_idx +
00103 _(DVD_REST_DURATION);
00104 break;
00105 case DVD_AudioTrackCount:
00106 key = _(DVD_TITLE) + title_idx + _(DVD_AUDIO_TRACK) + _(DVD_COUNT);
00107 break;
00108 case DVD_AudioTrackFormat:
00109 key = _(DVD_TITLE) + title_idx + _(DVD_AUDIO_TRACK) +
00110 audio_track_idx + _(DVD_FORMAT);
00111 break;
00112 case DVD_AudioTrackStreamID:
00113 key = _(DVD_TITLE) + title_idx + _(DVD_AUDIO_TRACK) +
00114 audio_track_idx + _(DVD_STREAM_ID);
00115 break;
00116 case DVD_AudioTrackChannels:
00117 key = _(DVD_TITLE) + title_idx + _(DVD_AUDIO_TRACK) +
00118 audio_track_idx + _(DVD_CHANNELS);
00119 break;
00120 case DVD_AudioTrackSampleFreq:
00121 key = _(DVD_TITLE) + title_idx + _(DVD_AUDIO_TRACK) +
00122 audio_track_idx + _(DVD_SAMPLE_FREQUENCY);
00123 break;
00124 case DVD_AudioTrackLanguage:
00125 key = _(DVD_TITLE) + title_idx + _(DVD_AUDIO_TRACK) +
00126 audio_track_idx + _(DVD_LANGUAGE);
00127 break;
00128 default:
00129 throw _Exception(_("Invalid dvd aux key name!"));
00130 }
00131
00132 return key;
00133 }
00134
00135 void DVDHandler::fillMetadata(Ref<CdsItem> item)
00136 {
00137 try
00138 {
00139 Ref<DVDNavReader> dvd(new DVDNavReader(item->getLocation()));
00140
00141 item->setFlag(OBJECT_FLAG_DVD_IMAGE);
00142
00143 int titles = dvd->titleCount();
00144 item->setAuxData(renderKey(DVD_TitleCount), String::from(titles));
00145
00146 for (int i = 0; i < titles; i++)
00147 {
00148 dvd->selectPGC(i, 0);
00149 item->setAuxData(renderKey(DVD_ChapterCount, i),
00150 String::from(dvd->chapterCount(i)));
00151
00152
00153
00154 item->setAuxData(renderKey(DVD_AudioTrackCount, i),
00155 String::from(dvd->audioTrackCount()));
00156
00157 for (int a = 0; a < dvd->audioTrackCount(); a++)
00158 {
00159 item->setAuxData(renderKey(DVD_AudioTrackFormat, i, 0, a),
00160 dvd->audioFormat(a));
00161 item->setAuxData(renderKey(DVD_AudioTrackStreamID, i, 0, a),
00162 String::from(dvd->audioStreamID(a)));
00163 item->setAuxData(renderKey(DVD_AudioTrackChannels, i, 0, a),
00164 String::from(dvd->audioChannels(a)));
00165 item->setAuxData(renderKey(DVD_AudioTrackSampleFreq, i, 0, a),
00166 String::from(dvd->audioSampleFrequency(a)));
00167 item->setAuxData(renderKey(DVD_AudioTrackLanguage, i, 0, a),
00168 dvd->audioLanguage(a));
00169 }
00170 #if 0
00171 int secs = 0;
00172 for (int c = dvd->chapterCount(i)-1; c >= 0; c--)
00173 {
00174 int chap_secs = dvd->chapterDuration(c);
00175 secs = secs + chap_secs;
00176 log_debug("Chapter seconds: %d rest seconds: %d\n", chap_secs,
00177 secs);
00178 if (chap_secs > 0)
00179 item->setAuxData(renderKey(DVD_ChapterDuration, i, c),
00180 secondsToHMS(chap_secs));
00181 if (secs > 0)
00182 item->setAuxData(renderKey(DVD_ChapterRestDuration, i, c),
00183 secondsToHMS(secs));
00184 }
00185 #endif
00186 }
00187
00188 log_debug("DVD image %s has %d titles\n", item->getLocation().c_str(),
00189 titles);
00190 }
00191 catch (Exception ex)
00192 {
00193 log_warning("Parsing ISO image failed (not a DVD?): %s\n", ex.getMessage().c_str());
00194 }
00195 }
00196
00197
00198
00199 Ref<IOHandler> DVDHandler::serveContent(Ref<CdsItem> item, int resNum, off_t *data_size)
00200 {
00201 *data_size = -1;
00202 return nil;
00203 }
00204
00205 #endif // HAVE_DVD