+void eDVBServicePlay::loadCuesheet()
+{
+ std::string filename = m_reference.path + ".cuts";
+
+ m_cue_entries.clear();
+
+ FILE *f = fopen(filename.c_str(), "rb");
+
+ if (f)
+ {
+ eDebug("loading cuts..");
+ while (1)
+ {
+ unsigned long long where;
+ unsigned int what;
+
+ if (!fread(&where, sizeof(where), 1, f))
+ break;
+ if (!fread(&what, sizeof(what), 1, f))
+ break;
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ where = bswap_64(where);
+#endif
+ what = ntohl(what);
+
+ if (what > 2)
+ break;
+
+ m_cue_entries.insert(cueEntry(where, what));
+ }
+ fclose(f);
+ eDebug("%d entries", m_cue_entries.size());
+ } else
+ eDebug("cutfile not found!");
+
+ m_cuesheet_changed = 0;
+ cutlistToCuesheet();
+ m_event((iPlayableService*)this, evCuesheetChanged);
+}
+
+void eDVBServicePlay::saveCuesheet()
+{
+ std::string filename = m_reference.path + ".cuts";
+
+ FILE *f = fopen(filename.c_str(), "wb");
+
+ if (f)
+ {
+ unsigned long long where;
+ int what;
+
+ for (std::multiset<cueEntry>::iterator i(m_cue_entries.begin()); i != m_cue_entries.end(); ++i)
+ {
+#if BYTE_ORDER == BIG_ENDIAN
+ where = i->where;
+#else
+ where = bswap_64(i->where);
+#endif
+ what = htonl(i->what);
+ fwrite(&where, sizeof(where), 1, f);
+ fwrite(&what, sizeof(what), 1, f);
+
+ }
+ fclose(f);
+ }
+
+ m_cuesheet_changed = 0;
+}
+
+void eDVBServicePlay::cutlistToCuesheet()
+{
+ if (!m_cue)
+ {
+ eDebug("no cue sheet");
+ return;
+ }
+ m_cue->clear();
+
+ if (!m_cutlist_enabled)
+ {
+ m_cue->commitSpans();
+ eDebug("cutlists where disabled");
+ return;
+ }
+
+ pts_t in = 0, out = 0, length = 0;
+
+ getLength(length);
+
+ std::multiset<cueEntry>::iterator i(m_cue_entries.begin());
+
+ while (1)
+ {
+ if (i == m_cue_entries.end())
+ out = length;
+ else {
+ if (i->what == 0) /* in */
+ {
+ in = i++->where;
+ continue;
+ } else if (i->what == 1) /* out */
+ out = i++->where;
+ else /* mark */
+ {
+ i++;
+ continue;
+ }
+ }
+
+ if (in != out)
+ m_cue->addSourceSpan(in, out);
+
+ in = length;
+
+ if (i == m_cue_entries.end())
+ break;
+ }
+ m_cue->commitSpans();
+}
+