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

Add support for XML embedded in chains #1047

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/mlt++/MltChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "MltChain.h"

#include <cstring>

using namespace Mlt;

Chain::Chain()
Expand All @@ -34,6 +36,12 @@ Chain::Chain(Profile &profile, const char *id, const char *service)
}

mlt_producer source = mlt_factory_producer(profile.get_profile(), id, service);
if (source
&& !strcmp("xml", mlt_properties_get(MLT_PRODUCER_PROPERTIES(source), "mlt_service"))) {
mlt_producer_close(source);
// Always use a producer-consumer for xml so that the profile can be changed
source = mlt_factory_producer(profile.get_profile(), "consumer", service);
Comment on lines +42 to +43
Copy link
Member

Choose a reason for hiding this comment

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

I noticed when recently debugging a related issue in Shotcut that the XML as Clip already gets a consumer producer if the profiles mismatch (a feature of the loader producer). Is that different when using a chain? It is not very desirable to add knowledge about certain modules within the framework proper. It is not a hard rule but rather a goal to minimize it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I noticed this too. When encapsulating XML producer in a chain, the problem becomes that sometimes that producer would be wrapped in consumer producer and sometimes it would not. The chain needs to be able to change the profile on the encapsulated producer. The XML producer does not support this very well because it does not propagate the profile change down to the producers inside of it. Forcing it to always use the producer_consumer works around that problem.

It is not very desirable to add knowledge about certain modules within the framework proper.

I agree - and I would prefer a generic way to do this. Another option would be to add a private property to producers called "_mutable_profile". If the profile can be changed (like avformat), then the property would be true. If the profile can not be changed (like xml), the property would be false. That could be the condition to decide if a producer_consumer should be used.

}
if (source) {
instance = mlt_chain_init(profile.get_profile());
mlt_chain_set_source(instance, source);
Expand Down
36 changes: 32 additions & 4 deletions src/modules/avformat/link_avdeinterlace.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ static int link_get_image(mlt_frame frame,
// Operate on the native image format/size;
srcimg.width = mlt_properties_get_int(unique_properties, "width");
srcimg.height = mlt_properties_get_int(unique_properties, "height");
srcimg.format = mlt_properties_get_int(unique_properties, "format");
if (mlt_properties_exists(unique_properties, "format")) {
srcimg.format = mlt_properties_get_int(unique_properties, "format");
} else {
srcimg.format = *format;
}

// Sanitize the input
if (srcimg.width <= 1 || srcimg.height <= 1) {
Expand Down Expand Up @@ -522,10 +526,34 @@ static int link_get_frame(mlt_link self, mlt_frame_ptr frame, int index)
return error;
}

// Pass original producer dimensions with the frame
mlt_properties unique_properties = mlt_frame_unique_properties(*frame, MLT_LINK_SERVICE(self));
mlt_properties_pass_list(unique_properties,
MLT_PRODUCER_PROPERTIES(original_producer),
"width height format");
mlt_properties original_producer_properties = MLT_PRODUCER_PROPERTIES(original_producer);
if (mlt_properties_exists(original_producer_properties, "width")) {
mlt_properties_set_int(unique_properties,
"width",
mlt_properties_get_int(original_producer_properties, "width"));
} else if (mlt_properties_exists(original_producer_properties, "meta.media.width")) {
mlt_properties_set_int(unique_properties,
"width",
mlt_properties_get_int(original_producer_properties,
"meta.media.width"));
}
if (mlt_properties_exists(original_producer_properties, "height")) {
mlt_properties_set_int(unique_properties,
"height",
mlt_properties_get_int(original_producer_properties, "height"));
} else if (mlt_properties_exists(original_producer_properties, "meta.media.height")) {
mlt_properties_set_int(unique_properties,
"height",
mlt_properties_get_int(original_producer_properties,
"meta.media.height"));
}
if (mlt_properties_exists(original_producer_properties, "format")) {
mlt_properties_set_int(unique_properties,
"format",
mlt_properties_get_int(original_producer_properties, "format"));
}

// Pass future frames
int i = 0;
Expand Down
16 changes: 16 additions & 0 deletions src/modules/core/producer_consumer.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ mlt_producer producer_consumer_init(mlt_profile profile,
mlt_properties properties = MLT_PRODUCER_PROPERTIES(self);
mlt_properties_set(properties, "resource", arg);
mlt_properties_pass_list(properties, MLT_PRODUCER_PROPERTIES(real_producer), "out, length");
mlt_properties_set_int(properties, "meta.media.width", temp_profile->width);
mlt_properties_set_int(properties, "meta.media.height", temp_profile->height);
mlt_properties_set_int(properties, "meta.media.progressive", temp_profile->progressive);
mlt_properties_set_int(properties,
"meta.media.frame_rate_num",
temp_profile->frame_rate_num);
mlt_properties_set_int(properties,
"meta.media.frame_rate_den",
temp_profile->frame_rate_den);
mlt_properties_set_int(properties,
"meta.media.sample_aspect_num",
temp_profile->sample_aspect_num);
mlt_properties_set_int(properties,
"meta.media.sample_aspect_den",
temp_profile->sample_aspect_den);
mlt_properties_set_int(properties, "meta.media.colorspace", temp_profile->colorspace);

// Done with the producer - will re-open later when we have the profile property
mlt_producer_close(real_producer);
Expand Down
19 changes: 18 additions & 1 deletion src/modules/core/producer_melt.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,24 @@ mlt_producer producer_melt_init(mlt_profile profile,
if (title == NULL && strstr(argv[i], "<?xml") != argv[i])
title = argv[i];

producer = create_producer(profile, field, argv[i]);
if (chain != NULL) {
// Clone the profile so that it can be changed as needed by the chain without changing the main profile
mlt_profile native_profile = mlt_profile_clone(profile);
native_profile->is_explicit = 0;
producer = create_producer(native_profile, field, argv[i]);
if (producer) {
mlt_properties_set_data(MLT_PRODUCER_PROPERTIES(producer),
"_native_profile",
native_profile,
0,
(mlt_destructor) mlt_profile_close,
NULL);
} else {
mlt_profile_close(native_profile);
}
} else {
producer = create_producer(profile, field, argv[i]);
}
if (!first_producer) {
first_producer = producer;
}
Expand Down