Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate type=codec metadata for gstreamer packages #45

Merged
merged 2 commits into from Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -83,3 +83,4 @@ optimizePNGSize | Use `optipng` to reduce the size of PNG images. Optipng needs
metadataTimestamps | Write timestamps into generated metadata files. *Default: `ON`*
immutableSuites | Allow suites to be marked as immutable. This is useful for distributions with fixed releases, but not for rolling release distributions or continuously updated repositories. *Default: `ON`*
processFonts | Include font metadata and render fonts. *Default: `ON`*
processGStreamer | Synthesise `type=codec` metadata from available GStreamer packages. Requires support in the backend, currently only implemented for Debian. *Default: `ON`*
@@ -41,6 +41,8 @@ private:
string pkgarch;
string pkgmaintainer;
string[string] desc;
string[string] summ;
GStreamer gstreamer;

bool contentsRead;
string[] contentsL;
@@ -56,7 +58,11 @@ public:
final @property override string ver () const { return pkgver; }
final @property override string arch () const { return pkgarch; }

final @property override GStreamer gst () { return gstreamer; }
final @property void gst (GStreamer gst) { gstreamer = gst; }

final @property override const(string[string]) description () const { return desc; }
final @property override const(string[string]) summary () const { return summ; }

override final
@property string filename () const {
@@ -99,6 +105,11 @@ public:
desc[locale] = text;
}

final void setSummary (string text, string locale)
{
summ[locale] = text;
}

private auto openPayloadArchive ()
{
auto pa = new ArchiveDecompressor ();
@@ -141,6 +141,12 @@ public:
if (split.length < 2)
continue;


if (lang == "en")
(*pkgP).setSummary (split[0], "C");

(*pkgP).setSummary (split[0], lang);

// NOTE: .remove() removes the element, but does not alter the
// length of the array. Bug? (this is why we slice the array
// here)
@@ -203,6 +209,9 @@ public:

DebPackage[string] pkgs;
do {
import std.algorithm : map;
import std.array : array;

auto name = tagf.readField ("Package");
auto ver = tagf.readField ("Version");
auto fname = tagf.readField ("Filename");
@@ -213,6 +222,28 @@ public:
pkg.filename = buildPath (rootDir, fname);
pkg.maintainer = tagf.readField ("Maintainer");

immutable decoders = tagf.readField("Gstreamer-Decoders")
.split(";")
.map!strip.array;

immutable encoders = tagf.readField("Gstreamer-Encoders")
.split(";")
.map!strip.array;

immutable elements = tagf.readField("Gstreamer-Elements")
.split(";")
.map!strip.array;

immutable uri_sinks = tagf.readField("Gstreamer-Uri-Sinks")
.split(";")
.map!strip.array;

immutable uri_sources = tagf.readField("Gstreamer-Uri-Sources")
.split(";")
.map!strip.array;

pkg.gst = new GStreamer(decoders, encoders, elements, uri_sinks, uri_sources);

if (!pkg.isValid ()) {
logWarning ("Found invalid package (%s)! Skipping it.", pkg.toString ());
continue;
@@ -26,6 +26,38 @@ import std.string;
import std.container;
public import asgen.datastore;

class GStreamer
{
immutable string[] decoders;
immutable string[] encoders;
immutable string[] elements;
immutable string[] uri_sinks;
immutable string[] uri_sources;

@property @safe pure bool isNotEmpty() {
return !(decoders.empty &&
encoders.empty &&
elements.empty &&
uri_sinks.empty &&
uri_sources.empty);
}

this () {
decoders = encoders = elements = uri_sinks = uri_sources = [];
}

this (immutable string[] decoders,
immutable string[] encoders,
immutable string[] elements,
immutable string[] uri_sinks,
immutable string[] uri_sources) {
this.decoders = decoders;
this.encoders = encoders;
this.elements = elements;
this.uri_sinks = uri_sinks;
this.uri_sources = uri_sources;
}
}

/**
* Represents a distribution package in the generator.
@@ -45,6 +77,14 @@ abstract class Package
*/
@property const(string[string]) description () const;

/**
* A associative array containing package summaries.
* Key is the language (or locale), value the summary.
*
* E.g.: ["en": "foo the bar"]
*/
@property const(string[string]) summary () const { return (string[string]).init; };

/**
* Filename of the package. This string is only used for
* issue reporting and other information, the file is never
@@ -68,6 +108,8 @@ abstract class Package
*/
abstract void close () {};

@property GStreamer gst () { return new GStreamer(); }

/**
* Retrieve backend-specific translations.
*
@@ -81,7 +81,8 @@ enum GeneratorFeature
OPTIPNG = 1 << 4,
METADATA_TIMESTAMPS = 1 << 5,
IMMUTABLE_SUITES = 1 << 6,
PROCESS_FONTS = 1 << 6
PROCESS_FONTS = 1 << 7,
PROCESS_GSTREAMER = 1 << 8,
}

final class Config
@@ -377,6 +378,7 @@ public:
setFeature (GeneratorFeature.METADATA_TIMESTAMPS, true);
setFeature (GeneratorFeature.IMMUTABLE_SUITES, true);
setFeature (GeneratorFeature.PROCESS_FONTS, true);
setFeature (GeneratorFeature.PROCESS_GSTREAMER, true);

// apply vendor feature settings
if ("Features" in root.object) {
@@ -407,6 +409,9 @@ public:
case "processFonts":
setFeature (GeneratorFeature.PROCESS_FONTS, featuresObj[featureId].type == JSON_TYPE.TRUE);
break;
case "processGStreamer":
setFeature (GeneratorFeature.PROCESS_GSTREAMER, featuresObj[featureId].type == JSON_TYPE.TRUE);
break;
default:
break;
}
@@ -155,8 +155,9 @@ public:
**/
private bool seedContentsData (Suite suite, string section, string arch)
{
bool packageInteresting (const string[] contents)
bool packageInteresting (Package pkg)
{
auto contents = pkg.contents;
foreach (ref c; contents) {
if (c.startsWith ("/usr/share/applications/"))
return true;
@@ -166,7 +167,7 @@ public:
return true;
}

return false;
return pkg.gst.isNotEmpty;
}

// check if the index has changed data, skip the update if there's nothing new
@@ -223,7 +224,7 @@ public:
}

// check if we can already mark this package as ignored, and print some log messages
if (!packageInteresting (contents)) {
if (!packageInteresting (pkg)) {
dstore.setPackageIgnore (pkid);
logInfo ("Scanned %s, no interesting files found.", pkid);
// we won't use this anymore
@@ -19,6 +19,7 @@

module asgen.extractor;

import std.array : appender;
import std.stdio;
import std.string;
import std.path : baseName;
@@ -200,6 +201,24 @@ public:
gres.updateComponentGCID (cpt, ddata);
}

if (conf.featureEnabled (GeneratorFeature.PROCESS_GSTREAMER) && pkg.gst.isNotEmpty) {
auto data = appender!string;
auto cpt = new Component ();

data.reserve(512);

cpt.setId (pkg.name);
cpt.setKind (ComponentKind.CODEC);
cpt.setName ("GStreamer Multimedia Codecs", "C");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not translated - not specific to the package in use. I don't know how to get anything better for here.

foreach (ref lang, ref desc; pkg.summary) {
cpt.setSummary (desc, lang);
data ~= desc;
}

gres.addComponent (cpt);
gres.updateComponentGCID (cpt, data.data);
}

auto hasFontComponent = false;
foreach (ref cpt; gres.getComponents ()) {
auto gcid = gres.gcidForComponent (cpt);